I am trying to add items to a ListView/Adapter from my MainActivity and use it across ListHelper.
I have it declared in Registrant.
public static List<Registrant> searchList = new ArrayList<Registrant>();
And then I add to it from MainActivity..
Registrant.searchList.add(registrant);
Then I try to retrieve this into a listview from the ListHelper.
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
adapter = new CustomListAdapter(this, Registrant.searchList);
adapter.notifyDataSetChanged();
But no luck, it is a blank screen?
Any ideas would be helpful.. thank you!
Instead of creating object of CustomListAdapter
class for updating data in ListView data-source. create a method in CustomListAdapter
class for adding data in List which is used by Adapter as data-source :
In CustomListAdapter
class add following method:
public void addItems(){
arrList.addAll(Registrant.searchList);
this.notifyDataSetChanged();
}
Now call addItems
method when want to update data in ListView:
listView.setAdapter(adapter);
adapter.addItems();