Как мы можем найти элемент класса адаптера в классе фрагмента в android ?
package com.example.aaa.maaqualatnew.adapter; import android.content.Context; import android.database.Cursor; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import com.bumptech.glide.Glide; import com.example.aaa.maaqualatnew.Global.GlobalData; import com.example.aaa.maaqualatnew.R; import com.example.aaa.maaqualatnew.databasehandler.DataBaseHandler; import com.example.aaa.maaqualatnew.extra.GeneralUtilities; import com.example.aaa.maaqualatnew.fragment.CategoryFragment; import com.example.aaa.maaqualatnew.model.PojoCategory; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class CategoryAdapter extends BaseAdapter { private ArrayList<PojoCategory> mList; private Context mContext; private ViewHolder viewHolder; private DataBaseHandler dbh; public CategoryAdapter(Context mContext, ArrayList<PojoCategory> mList) { this.mContext = mContext; this.mList = mList; dbh = new DataBaseHandler(mContext); } @Override public int getCount() { if (mList != null) { return mList.size(); } return 0; } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View view, ViewGroup parent) { LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (view == null) { view = layoutInflater.inflate(R.layout.category, parent, false); viewHolder = new ViewHolder(); viewHolder.Dish_name = (TextView) view.findViewById(R.id.nameofdish); viewHolder.dish_description = (TextView) view.findViewById(R.id.dishdescription); viewHolder.Dish_rate = (TextView) view.findViewById(R.id.rateofdish); viewHolder.item_image = (ImageView) view.findViewById(R.id.img_item); // viewHolder.btnAddCart = (Button) view.findViewById(R.id.btn_add_cart); viewHolder.tv_Number = (TextView) view.findViewById(R.id.tv_add_sub); viewHolder.mBtnAdd = (Button) view.findViewById(R.id.btn_add); viewHolder.mBtnMinus = (Button) view.findViewById(R.id.btn_sub); } else { viewHolder = (ViewHolder) view.getTag(); } view.setTag(viewHolder); final PojoCategory pojoCategory = (PojoCategory) getItem(position); viewHolder.Dish_name.setText(pojoCategory.getDish_name()); viewHolder.dish_description.setText(pojoCategory.getdish_description()); viewHolder.Dish_rate.setText(pojoCategory.getDish_rate()); Glide.with(mContext).load(pojoCategory.getCategory_Image()).into(viewHolder.item_image); // viewHolder.btnAddCart.setTag(position); /* viewHolder.btnAddCart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String tag = viewHolder.btnAddCart.getTag().toString(); int position = Integer.parseInt(tag); } });*/ viewHolder.mBtnAdd.setTag(pojoCategory); viewHolder.mBtnMinus.setTag(pojoCategory); if (pojoCategory.getmQuantity() > 0) { viewHolder.tv_Number.setText("" + pojoCategory.getmQuantity()); } else { viewHolder.tv_Number.setText("" + 0); } viewHolder.mBtnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PojoCategory pojoCategory = (PojoCategory) v.getTag(); int mValue = pojoCategory.getmQuantity(); mValue++; viewHolder.tv_Number.setText("" + mValue); pojoCategory.setmQuantity(mValue); notifyDataSetChanged(); dbh.insertData(pojoCategory.getDish_name(), pojoCategory.getDish_rate(), pojoCategory.getCategory_Image()); } }); viewHolder.mBtnMinus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PojoCategory pojoCategory = (PojoCategory) v.getTag(); int mValue = pojoCategory.getmQuantity(); if (mValue > 0) { mValue--; viewHolder.tv_Number.setText("" + mValue); } pojoCategory.setmQuantity(mValue); notifyDataSetChanged(); } }); return view; } class ViewHolder { TextView Dish_name, dish_description, Dish_rate, tv_Number; ImageView item_image; // Button btnAddCart; Button mBtnAdd, mBtnMinus; } }
Что я уже пробовал:
я хочу найти элемент класса адаптера в классе фрагмента ! если кто-нибудь скажет мне, как я могу это сделать ??
Richard MacCutchan
Какой предмет? Где вы пытаетесь получить к нему доступ?