Changing TextView value in custom ListView

Let's assume we have this example:

with source code available here:

How can we change the mobile phone number after clicking on the list item?


source to share

1 answer

In the method, onItemClick()

get the element PhoneBook

corresponding to the position (position parameter) of the clicked row, update the value, and then notify the adapter that the data changed with a method call notifyDataSetChanged()


list.setOnItemClickListener(new OnItemClickListener() {

            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
                // notify the adapter that something has changed




All Articles