martin k.
martin k.

Reputation: 166

ListView feeded with more adapters acording to need

I'm pretty much new in Android coding. I have simple app where there is, amongst other views, a ListView.

Now, when a 'bystanding' button is clicked, I need the ListView to change it's content... there are actualy three modes in which the ListView can be, now I was thinking how to change the content(the user can change it many times instantly to any mode he wants) the best way.

I know I can just rewrite the data of the adapter and call 'notifyDataSetChanged', but I think for me it's better to create several adapters and attach them to the listView whenever I want... is that even possible? I've already tried that and it doesn't work how I want:

The first mode that is chosen just when the app onCreates has seven items. The second ones have each two completely different items. What I have done was just calling the 'setAdapter' method and all that happened was that there were just two OF THE PREVIOUS(seven-itemed) ADAPTER.

Even when I write at the end

listView.invalidate();
adapter.notifyDataSetChanged();

Hope You understand what I'm trying to say. Is it OK to attach another adapter just when I want? Shall I just change the data of one? Please help.

Upvotes: 0

Views: 42

Answers (1)

Kartheek
Kartheek

Reputation: 7214

Is it OK to attach another adapter just when I want?

           Maintaining the multiple instances of adapter for a single ListView is not a good idea.
Instead of maintaining the multiple adapter instances, maintain a single instance of the adapter and update the data in the adapter using

adapter.notifyDataSetChanged();

Upvotes: 1

Related Questions