私はすでにこの問題を解決するために多くの時間を費やしました、私はこのトピックについて他の多くのStackOverflow投稿を見ましたが、私のために働く解決策を見つけることができませんでした。
ListActivityとカスタムArrayAdapterがあります。リストビューには、削除ボタンなど、いくつかのボタンがあります。ただし、onItemClickメソッドは、リストのTextViewがクリックされた場合にのみ呼び出されます。OnClickListenersをボタンに追加することはできますが、ボタンが属する要素の位置がわからないという問題があります。すべてのボタンにタグを設定できることは知っていますが、それを行うにはもっと良い方法が必要です。
これは私のアダプターです:
private class ItemListAdapter extends ArrayAdapter<Item> {
private ArrayList<Item> items;
private int countItems = 0;
public ItemListAdapter(Context ctx, int textViewResourceId, ArrayList<Item> itemList){
super(ctx, textViewResourceId, itemList);
this.items = itemList;
this.countItems = itemList.size();
}
public int getCount(){
return countItems;
}
public Item getItem(int pos){
return itemList.get(pos);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
//Get the current list item
final Item currentItem = itemList.get(position);
if (row == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = vi.inflate(R.layout.itemlist_item_row, null);
}
Item item = items.get(position);
if (item != null){
TextView bt = (TextView) row.findViewById(R.id.bt_itemlist_item);
if (bt != null){
bt.setText(item.getName());
}
}
return row;
}
}
誰かがこれに対する最善の解決策を教えてくれたら素晴らしいと思います。