0

I have created a ListView that is displaying the items perfectly. But I want to display subitem with each item of ListView.

How can I do that?

my code:

public class ListDisplay extends AppCompatActivity {

    String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry","WebOS","Ubuntu","Windows7","Max OS X"};
    public static ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_display);

        listView = (ListView) findViewById(R.id.listViewItems);
        ArrayAdapter adapter = new ArrayAdapter<String>(context, R.layout.activity_listview, mobileArray);
        ListDisplay.listView.setAdapter(adapter);
    }

}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sajal Ali
  • 427
  • 1
  • 10
  • 21
  • 1
    Possible duplicate of [Android Custom Layout for listview](http://stackoverflow.com/questions/19615766/android-custom-layout-for-listview) – Reaz Murshed May 05 '16 at 18:10
  • There are many examples of having a custom layout in a `ListView` in Stackoverflow. Please try searching for one first. – Reaz Murshed May 05 '16 at 18:11
  • Note: You don't need `static` variables here. (Also, it isn't good practice to use them in Android) – OneCricketeer May 05 '16 at 21:04

1 Answers1

0

The possible solution for your question is the Expandable ListView, with this component you can do a listview where every element in that list contains a multiple elements inside. I let you a link with an example.

Expandable Listview

If you need some more custom help with your code, we can help you if you post a situation more detailed.

Chefes
  • 1,892
  • 18
  • 17
  • I'm wouldn't go as far as an ExpandableListView. It sounds like only a custom View that is more complex than `toString`-ing all the data is wanted. – OneCricketeer May 05 '16 at 21:03