我有一个适配器来在ListView中呈现扩展BaseAdapter的值。 在活动中调用此适配器。 Activity有一个TextView,需要在Adapter中调用onClickListener时更新。 如果在适配器中单击按钮,有人可以告诉我如何更新TextView。 任何例子都会有所帮助。 感谢。
码
private class ViewItem extends Activity{
ImageButton addToCart;
ViewItem(View convertView,final int position)
{
addToCart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
itemPosition=Integer.parseInt(positionView.getText().toString());
int qty = Integer.parseInt(quantity.getText().toString());
ShoppingCartHelper.setQuantity(itemPosition, qty);
ShoppingCartHelper.itemsInTheCart = ShoppingCartHelper.cartMap.size();
Toast.makeText(v.getContext(), "Successfully, Item added to the Cart...", Toast.LENGTH_SHORT).show();
//I need to update a TextView here
// Close the activity
finish();
}
});
答案 0 :(得分:0)
试试这个,
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
EvenViewHolder holdereven;
if (convertView == null) {
convertView = mInfaltor.inflate(R.layout.schedule_adapter_view,
null);
holdereven = new EvenViewHolder();
holdereven.time = (TextView) convertView
.findViewById(R.id.time);
holdereven.title = (TextView) convertView
.findViewById(R.id.title);
holdereven.des = (TextView) convertView.findViewById(R.id.des);
holdereven.time.setOnClickListener(new View.OnClickListener(
) {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Do your stuff
}
});
convertView.setTag(holdereven);
} else {
holdereven = (EvenViewHolder) convertView.getTag();
}
static class EvenViewHolder {
TextView time, title, des;
}
}