0

I have three ListFragment is one activity. For the first listFragment I have created a ListFragment and inflate a layout with some listItem easily:

setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getResources.getStringArray(R.string.baal)));

The item of the second listFragment will change according to the selected item of the first ListFragment and in the similar way The item of the third listFragment will change according to the selected item of the second ListFragment.

The first ListFragment is static as it won't depend on any other ListFragment. So I simply inflate a layout with some item for it.

But The items of second and third listFragments need to be changed frequently. So I need to inflate it in run-time with new listitems every time on click event. So I think the second and third LisFragment needs to be create dynamically by inflating every-time with new list items. How can I achieve that? I am new in Fragment and I need my concept on dynamic UI clear. Thanks in advance.

ridoy
  • 6,274
  • 2
  • 29
  • 60
Kaidul
  • 15,409
  • 15
  • 81
  • 150

2 Answers2

1

You can, for example, try to clear your adapters of second and third fragments and then add all necessary items, this way you would not need to inflate the whole fragments, but instead only the content would change. Also depending on adapter types you would need to call notifyDataSetChanged or not (if it is ArrayAdapter for example).

UPD: On your main item click event you can write some code like this

            YourAdapter1 adapter1 = getFirstAdapter();
            adapter1.clear();
            adapter1.addAll(newItem1Collection);

            YourAdapter2 adapter2 = getSecondAdapter();
            adapter2.clear();
            adapter2.addAll(newItem2Collection);

where YourAdapter1 and YourAdapter2 should extend ArrayAdapter, this will also automatically invoke notifyDataSetChange.

Desert
  • 2,293
  • 15
  • 16
0

I suggest you use tabs, adding tabs dynamically for each selection, and allowing the user to swipe back to cancel a selection, something like breadcrumbs navigation.

You can see the related question here: Android - How to create tabs on demand using existing layout?

Community
  • 1
  • 1
Steelight
  • 3,347
  • 1
  • 20
  • 17
  • I am using navigation drawer. So I don't want use tab navigation :( – Kaidul Jul 14 '13 at 09:10
  • you can still use the same idea, without showing the tabs themselves. Each selection will scroll the list sideways to reveal a lower level, and the back button will return one level up. – Steelight Jul 14 '13 at 09:54