【安卓笔记】ArrayAdapter删除item注意事项
public void remove(T object) { synchronized (mLock) { if (mOriginalValues != null) { mOriginalValues.remove(object); } else { mObjects.remove(object); } } if (mNotifyOnChange) notifyDataSetChanged();//通知观察者 }
下面是ArrayAdapter使用示例:
mListView = (ListView) findViewById(R.id.lv); String[] data = { "aaaaaaaaaaaaaaaaaa","bbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaa","bbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaa","bbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaa","bbbbbbbbbbbbbbbb", }; final List<String> d = new ArrayList<String>(Arrays.asList(data)); mAdapter = new ArrayAdapter<String>(this, R.layout.item, R.id.tv,d); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(int postion) { mAdapter.remove(mAdapter.getItem(postion)); } });
public ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) { init(context, resource, textViewResourceId, Arrays.asList(objects)); }
List<String> d = new ArrayList<String>(Arrays.asList(data));
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。