我有一个使用自定义 listAdapter 设置的列表视图。每个 listView 项目中都有一个按钮来更改同一行中的 textView。我怎样才能做到?这是代码的一部分:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final int _position = position;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.activity_today_sales_list_view, null);
holder = new ViewHolder();
holder.txt_itemName = (TextView) convertView.findViewById(R.id.itemNameTB);
holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.priceTB);
holder.txt_plusBtn = (Button) convertView.findViewById(R.id.addBtn);
holder.txt_minusBtn = (Button) convertView.findViewById(R.id.minusBtn);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt_plusBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Plus Btn", "Clicked");
}
});
holder.txt_minusBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.d("Minus Btn", "Clicked");
}
});
holder.txt_itemName.setText(itemDetailsrrayList.get(position).getItemName());
holder.txt_itemPrice.setText(itemDetailsrrayList.get(position).getItemCost());
return convertView;
}