I have a listView inside a SherlockFragment, but I can not update the listView on screen when I make any changes to the Adapter. I tried: adapter.notifyDataSetChanged(), but without success. Thank's.
Asked
Active
Viewed 638 times
0
-
http://stackoverflow.com/questions/2250770/how-to-refresh-android-listview/2250849#2250849 Has all the info and things to consider you'll need. – KMDev Sep 03 '13 at 22:37
-
show some code. you're probably doing something wrong ... – gunar Sep 03 '13 at 22:40
2 Answers
1
You should be updating the underlying dataset that is passed to the adapter before calling notifyDatasetChanged();
EG:
For ArrayAdapter in a ListActivity ("arraylist" is the ArrayList you've used to back your ArrayAdapter)
arraylist.add(data);
arrayadapter = this.getListAdapter();
arrayadapter.notifyDatasetChanged();

James W
- 410
- 2
- 10
0
Personally, everytime user like press refresh button i repopulate listView initializing Cursor
again.
Like this: calling this function...
public void repopulateListView(){
cursor = dbHelper.fetchAll();
columns = new String[] {
DBAdapter.KEY_NAME,
DBAdapter.KEY_DATE,
DBAdapter.KEY_VOTE,
DBAdapter.KEY_CREDIT
};
to = new int[] {
R.id.one,
R.id.two,
R.id.three,
R.id.four
};
dataAdapter = new SimpleCursorAdapter(
getActivity(), R.layout.YOUR_ID,
cursor,
columns,
to,
0)
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final View row = super.getView(position, convertView, parent);
}
}
}
...from Refresh
onClick:
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.refresh:{
repopulateListView();
break;
}
}
}

Stefano Munarini
- 2,711
- 2
- 22
- 26