Skip to content Skip to sidebar Skip to footer

How Refresh A Listview Inside Sherlockfragment?

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 withou

Solution 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();

Solution 2:

Personally, everytime user like press refresh button i repopulate listView initializing Cursor again.

Like this: calling this function...

publicvoidrepopulateListView(){

cursor = dbHelper.fetchAll();
        columns = newString[] {                        
                DBAdapter.KEY_NAME,
                DBAdapter.KEY_DATE,
                DBAdapter.KEY_VOTE,
                DBAdapter.KEY_CREDIT
        };
        to = newint[] {
                R.id.one,
                R.id.two,
                R.id.three,
                R.id.four
        };

        dataAdapter = newSimpleCursorAdapter(
                getActivity(), R.layout.YOUR_ID,
                cursor,
                columns,
                to,
                0)
        {
            @Overridepublic View getView(int position, View convertView, ViewGroup parent)
            {
                finalViewrow=super.getView(position, convertView, parent);

            }
        }
        }

...from Refresh onClick:

@OverridepublicvoidonClick(View view) {
    switch (view.getId()){
        case R.id.refresh:{
            repopulateListView();
            break;
        }
    }
 }

Post a Comment for "How Refresh A Listview Inside Sherlockfragment?"