您好我有一個listview
及其適配器和對象類,每個listview位置都有一個按鈕,並且在適配器中有一個clicklistener,但是當我點擊我的button
listview
它返回最後一個項目的位置。從適配器中的onclick監聽器獲取listiview的對象
這裏是我的適配器:
public class comentario_adapter extends BaseAdapter {
protected Activity activity;
protected ArrayList<comentario_obj> items;
private Context mContext;
comentario_obj prod;
ImageButton correcta;
boolean marcada = false;
View vi;
public comentario_adapter(Activity activity, ArrayList<comentario_obj> items, Context context) {
this.activity = activity;
this.items = items;
this.mContext=context;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
vi=convertView;
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.comentario_adapter, null);
}
prod = items.get(position);
TextView title_coment = (TextView) vi.findViewById(R.id.title_coment);
ImageButton voteup= (ImageButton) vi.findViewById(R.id.voteup);
ImageButton votedown= (ImageButton) vi.findViewById(R.id.votedown);
title_coment.setText(prod.getTitulo());
ImageButton btn=(ImageButton)vi.findViewById(R.id.correcta);
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
if(mContext instanceof verPregunta_class){
((verPregunta_class) mContext).MyMethod();
//NEED THE TITLE OF LISTVIEW POSITION CLICKED
}
}
});
return vi;
}
public interface IMethodCaller{
void MyMethod();
}
}
天真的方式:讓'prod'本地最終或使用View.Tag ......也使用谷歌,問baziilion次 – Selvin
http://stackoverflow.com/questions/14782868/android-removing-item-from-listview- is-not-working-properly – Palejandro
是的,但是我該怎麼處理這個標籤? –