假设我们有这个例子:
http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html
源代码如下:
http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/
如何在单击列表项后修改移动电话号码?

最佳答案

在方法onItemClick()中,获取与所单击行的位置(position参数)对应的PhoneBook元素,更新该值,然后通过调用方法notifyDataSetChanged()通知适配器数据已更改:

list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position, long index) {
                // make the adapter a field in your class (or final)
                PhoneBook element = (PhoneBook) adapter.getItem(position);
                //modify the PhoneBook element
                element.setPhone("555-555-555");
                // notify the adapter that something has changed
                adapter.notifyDataSetChanged();
                showToast(listOfPhonebook.get(position).getName());
            }
        });

10-08 14:14