0

I’m new to android development… I want to pass data to 2 ListViews through an ARRAY . Should I use a 2D array.? Then how?

What I want to do is;

Eg:In ListView1 there are

Fruits

Vegetables

Meat

When you click on Fruits in listviv1 the results(Mango, Banana, Apple, PineApple) should be disply in ListView2. I know that I can use extendable ListViews but I don’t want to do in that way. I need to use 2 ListViews. So far i did;

    String items[] = { "Fruits", "Vegetables", "Jooses", "Meat", "Toys",
            "Cookeys" };

    String[][] groups = { { "Mango", "Banana", "Apple", "grapes", "paln" },
            { "Banana", "Apple", "grapes", "paln", "Green" },
            { "Red", "Green" }, { "Carrot" }

    listviv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            switch (arg2) {
            case 0:
                Listviv.setAdapter(adapter2);

                break;
            case 1:

                break;

            default:
                break;
            }

        }
Shazz
  • 25
  • 7

1 Answers1

0

I believe the ExpandableListView and ExpandableListAdapter are what you want. It is something looks like:

enter image description here

(Image from this artical which is a tutorial about ExpandableListView)

This and this will probably be helpful.

However, if you insist using one ListView, MergeAdapter can achieve this to some extent. This answer might be helpful.

Also, you can implement this using multiple fragments, i.e., the first fragment shows the category, and when click to any item, shows the second fragment that contains the detail.

Community
  • 1
  • 1
J Jiang
  • 1,452
  • 10
  • 14
  • thanks but i need to have 2 listviews. I know I can use an extandable listviv but in my case I need to have 2 listviews. this is a eg of what i want to do. but my reall app had 2 listviews – Shazz Feb 19 '14 at 05:43