自定義列表適配器類。android如何點擊列表視圖項中的按鈕來刪除該項
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.cart_item, null);
holder = new ViewHolder();
holder.image = (ImageView) convertView.findViewById(R.id.item_image);
holder.name = (TextView) convertView.findViewById(R.id.item_name);
holder.price = (TextView) convertView.findViewById(R.id.item_price);
holder.qty = (Spinner) convertView.findViewById(R.id.spinner_qty);
holder.delete_btn = (Button) convertView.findViewById(R.id.delete_btn);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
//holder.image
holder.name.setText(productArray.get(position).getName());
holder.price.setText("$"+ productArray.get(position).getPrice());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, quantity);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.qty.setAdapter(adapter);
return convertView;
}
如何點擊delete_btn刪除listview項。我不知道如何訪問列表視圖。請幫忙!
是的我知道,問題是如何訪問listview然後調用它的remove方法 – Jerryc
使用接口來溝通。您可以使用setTag方法 –
將它傳遞給按鈕嗎?或者我以後再做謝謝@ PiotrGolinski – Jerryc