0

次のように、カスタムアダプターを使用してAndroidリストビューで BaseAdapter を拡張しています。

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = getLayoutInflater();
    View row;
    row = inflater.inflate(R.layout.listview, parent, false);
    TextView textview = (TextView) row.findViewById(R.id.tv_main);
    ImageView imageview = (ImageView) row.findViewById(R.id.iv_main);
    textview.setText(data_text[position]);
    imageview.setImageResource(data_image[position]);
    imageview.setScaleType(ScaleType.FIT_XY);
    return (row);
}

私のリストを示しています。次に、longClickListener をアタッチして、削除オプションを提供するコンテキスト メニューを表示します。問題は、リスト内のインデックス付きの位置を削除した後、その位置への参照によって例外がスローされることです。私はnotifyDataSetChangedをさまざまな形式で試しましたが、成功しませんでした。ArrayAdapter を試しましたが、同じ問題が発生しました。これを回避する方法があるはずですが、私は打ちのめしています。提案やリンクをいただければ幸いです。

4

0 に答える 0