ListView每个Item位置都是Separate setOnClickListener

时间:2017-09-28 14:11:35

标签: android listview

我有一个listView,我想当我点击+(imageView)或 - (imageView),我的textView(tvCount)的数量发生变化,MyProblem是我想改变每个项目的数量单独更改当我点击每个+或 - 。 enter image description here

public class MyListAdapter extends BaseAdapter  {
Integer [] imgList = {R.drawable.kob,R.drawable.joje,
                        R.drawable.baarg,R.drawable.zereshk};
String [] nameList = {"کوبیده","جوجه","برگ","زرشک پلو"};

String [] subNameList = {"کوبیده","جوجه","برگ","زرشک پلو"};

String [] priceList = {"12000 تومان","14000 تومان","19000 تومان","13000 تومان"};

String [] tvCountList = {" 0 "," 0 "," 0 "," 0 "};

Context context;
LayoutInflater layoutInflater;
int count;
public MyListAdapter (Context context){
    this.context = context;
    layoutInflater=(LayoutInflater)context.getSystemService
            (Context.LAYOUT_INFLATER_SERVICE);

}


@Override
public int getCount() {
    return imgList.length;
}

@Override
public Object getItem(int position) {
    return imgList[position];
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View view, ViewGroup parent) {
    view = layoutInflater.inflate(R.layout.activity_my_list_adapter,null);
    ImageView imageViewList=(ImageView)view.findViewById(R.id.imageViewList);
    ImageView imgPlus=(ImageView)view.findViewById(R.id.imageViewPlus);
    ImageView imgNegative=(ImageView)view.findViewById(R.id.imageViewNegative);
    TextView tvName = (TextView)view.findViewById(R.id.textViewName);
    TextView tvSubName = (TextView)view.findViewById(R.id.textViewSubName);
    TextView tvPrice = (TextView)view.findViewById(R.id.textViewPrice);
    TextView tvCount = (TextView)view.findViewById(R.id.textViewCount);
    imgPlus.setImageResource(R.drawable.greenplus);
    imgNegative.setImageResource(R.drawable.rednegative);
    imageViewList.setImageResource(imgList[position]);
    tvName.setText(nameList[position]);
    tvSubName.setText(subNameList[position]);
    tvPrice.setText(priceList[position]);
    tvCount.setText(tvCountList[position]);

    return view;
}

}

0 个答案:

没有答案