android – 在自定义ListView中更改TextView值
作者:互联网
假设我们有这个例子:
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()方法中,获取与单击的行的位置(位置参数)对应的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());
}
});
标签:android,listview,android-listview,listadapter 来源: https://codeday.me/bug/20190902/1790127.html