user
user

Reputation: 2009

Refresh the listview in fragment android

I have a listview in left side fragment and dynamic fragment in right side.If a change is updates in right side view.I want to refresh the list view left side fragment.How to achieve this.

Any help would be greatly appreciated:)

Upvotes: 0

Views: 6638

Answers (2)

peregrinus
peregrinus

Reputation: 167

In my case the fragment OnCreate looks like this:

private MySQLiteHelper      databaseHelper;
private Cursor              c;
private myCursorAdapter     cursorDataAdapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle  savedInstanceState) {

                ViewContext = rootView.getContext();

                databaseHelper = new MySQLiteHelper(ViewContext);
                c = databaseHelper.myquery();
...
}

To update the listview I call from a different fragment, an update function defined inside the fragment containing the listview:

public void updatelistview()
{
    Cursor c = databaseHelper.myquery();
    connettiDataAdapter.changeCursor(c);
    connettiDataAdapter.notifyDataSetChanged();
});

Upvotes: 2

Praveen Sharma
Praveen Sharma

Reputation: 4348

Hope this help you :-

ListView list = (ListView) getActivity().findViewById(R.id.theIdOfTheList);
((BaseAdapter)list.getAdapter()).notifyDataSetChanged();

Upvotes: 1

Related Questions