标签:
ArrayAdapter提供了remove方法可以删除数据源中的数据,并使界面刷新。下面是其源码:public void remove(T object) { synchronized (mLock) { if (mOriginalValues != null) { mOriginalValues.remove(object); } else { mObjects.remove(object); } } if (mNotifyOnChange) notifyDataSetChanged();//通知观察者 }
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));
标签:
原文地址:http://blog.csdn.net/chdjj/article/details/42293713