I am using custom adapter to display a ListView.
It is working fine.
But i need to add three items to the ListView. How do I add them and have them display?
I tried notifydatasetchanged()
method that is not working.
I am using custom adapter to display a ListView.
It is working fine.
But i need to add three items to the ListView. How do I add them and have them display?
I tried notifydatasetchanged()
method that is not working.
For adding item into the listview you must use the List/ArrayList object. Using this you can perform add/edit/delete operation on listview item data and this list set into your adapter to get the data from list/arraylist and set into list item.
Ok now suppose I have listview and want to add new item just add item into the list/arraylist object and notify to the adapter like this
List<String> myList = new ArrayList<String>();
ArrayAdapter<String> adapter;
oncreate(){
// initi listview, adapter and set the myList object into adapter object and then set the adapter into listview
}
// on button click from somewhere
public void onClick(View view){
myList.add("hello friends");// you can add your data here into list object
adapter.notifyDataSetChanged();
}