2つのビュータイプListView
を拡張して持つカスタムアダプタを使用しています。BaseAdapter
メソッドを実行するadapter.removeRow(position)
と、アダプターのデータが正しく更新され、リストにこれが反映されますが、ビュータイプが正しく更新されません。アダプターはによって支えられています
ArrayList<Map<String, String>> rows = new ArrayList<Map<String, String>>();
そして私はサブセットを持っています
List<Integer> flashSet = new ArrayList<Integer>();
これは、(標準のビュータイプ0ではなく)ViewType1のすべての位置のリストです。
これが私のアダプタremoveRow(position)
メソッドです:
public void removeRow(int position) {
if (getItemViewType(position) == TYPE_FLASH) {
flashSet.remove(position);
}
for (int flashPosition:flashSet) {
System.out.println(tag+"is "+flashPosition+" going to be moved?");
if (flashPosition > position) {
flashPosition -= 1;
System.out.println(tag+"Yes! It's been moved to "+flashPosition);
}
}
rows.remove(position);
notifyDataSetChanged();
}
これが私のgetView
方法です:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
FlashHolder flashHolder;
ClipHolder clipHolder;
int type = getItemViewType(position);
if (convertView == null) {
if (type == TYPE_CLIP) {
convertView = rowInflater.inflate(R.layout.clip_note_row_layout, null);
clipHolder = new ClipHolder();
flashHolder = null;
clipHolder.textView = (TextView)(convertView.findViewById(R.id.clip_text));
convertView.setTag(clipHolder);
} else {
convertView = rowInflater.inflate(R.layout.flash_row_layout, null);
clipHolder = null;
flashHolder = new FlashHolder();
flashHolder.front = (TextView)(convertView.findViewById(R.id.flash_text));
flashHolder.back = (TextView)(convertView.findViewById(R.id.clip_text));
convertView.setTag(flashHolder);
}
} else {
if (type == TYPE_CLIP) {
clipHolder = (ClipHolder)convertView.getTag();
flashHolder = null;
} else {
clipHolder = null;
flashHolder = (FlashHolder)convertView.getTag();
}
}
if (type == TYPE_CLIP) {
clipHolder.textView.setText(rows.get(position).get("clip"));
} else {
flashHolder.front.setText(rows.get(position).get("flash_text"));
flashHolder.back.setText(rows.get(position).get("clip"));
}
return convertView;
}
私は新しいものを作成し、adapter
それを更新ArrayList
して呼び出すことができることを知っていますlistView.setAdapter(adapter)
が、潜在的に長いリストから1つのアイテムを削除しようとしているだけでは、これは完全にやり過ぎのようです。削除前と削除後の写真を参照してください。
次に、最初のアイテムを削除します。「Let'swatchit」アイテムの後ろに「which」という単語が隠されていましたが、「inspiredby…」アイテムは空白のアイテム3の後ろに隠されています。
したがって、データは更新されますが、ビュータイプは更新されません。助けてくれてありがとう!