Reputation: 135
I'm an Android beginner starting with fragments. My problem is the following.
I has a fragment that used to show a custom listview (it extended SherlockListFragment). I populated the listview with some data server. The action of retrieveing data of the server was executed in another thread and I had a handler to manage responses. In this handler (inside my fragment) I recovered data for my adapter and the I reloaded my adapter like this ((myAdapter) fragment.getListAdapter()).dataChange();
.
Well, now I wanted to convert the list in a custom grid cause I think it's much better for my app. So, the fragment doesn't extends SherlockListFragment, but BaseFragment. As I don't have a ListView anymore, I can't not use "getListAdapter.datachange()". Does anybody know the correct way to do this?
Thanks in advance.
Upvotes: 3
Views: 7585
Reputation: 135
thanks a lot for your quick responses. I tried your ideas but finally I converted my old list in a grid by making a two columns' row. It was the best option to keep my header and footer on.
Upvotes: 0
Reputation: 18381
Make an Adapter for the gridview that extends from BaseAdapter, or use an Adapter that extends from BaseAdapter.
then call notifyDataSetChanged on that adapter when the contents of your collection has changed.
Small example of adapter and grid
Upvotes: 3
Reputation: 2495
I would recommend making your changes on the Adapter, not the Grid (or list). Depending on the type of adapter you are using there are a couple different approaches.
For an ArrayAdapter
, using the standard modification methods (add
, addAll
, clear
, remove
) should update any views.
A CursorAdapter
works in much the same way, except that you use either swapCursor
or changeCursor
to change the underlying data. That should notify all data set observers that the underlying data has changed.
If your observers don't get notified, usually because setNotifyOnChange
was called, you can call mAdapter.notifyDataSetChanged()
to manually update all listeners (UI views, services, etc.) that the underlying data has changed.
Upvotes: 1