0

my code is about a listview with sub item, I fill it with array string[] but only show me the first string, someone can I help me?

private String[] d1 = new String[5];

private String[] d2 = new String[5];

ArrayList<HashMap<String, String>> data;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
listView = (ListView) findViewById(R.id.list);

    for(int i=0;i<lengh;i++){
        Map<String,Object> daat = new HashMap<String, Object>();
        daat.put("title",  d1[i]);
        daat.put("sub", d2[i]);
        data.add(daat);
    }

    SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2,
            new String[]{"title", "sub"}, new int[]{android.R.id.text1, android.R.id.text2});

    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

my example

Andy R
  • 53
  • 6
  • 1
    problem here `i – IntelliJ Amiya Nov 04 '17 at 08:28
  • I've fixed it, but the result is the same – Andy R Nov 04 '17 at 18:54
  • 1
    In your image, you have several item dividers shown. Therefore it looks like your already got items in your list view but the content of the items are "". You may try in the for loop, replace d1[i] with d1[0] to see if other items can be shown. Hope that help! – i_A_mok Nov 05 '17 at 15:49

1 Answers1

2
 for(int i=0;i<d1.length;i++){
    Map<String,Object> daat = new HashMap<String, Object>();
    daat.put("title",  d1[i]);
    daat.put("sub", d2[i]);
    data.add(daat);
 }

hear in for loop specify which string length and try i hope it work .

Payal Sorathiya
  • 756
  • 1
  • 8
  • 23