Элемент и подэлемент в ListView - PullRequest
2 голосов
/ 20 декабря 2011

Я хочу показать Элемент и соответствующий подпункт в виде списка, используя Arrayadapter и android.R.layout.simple_list_item_2. Я могу перечислить элементы со следующим кодом

XML-файл:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="8dp" >

<ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Empty set" />

Java-файл:

public class Lists extends ListActivity {    
    String[] listItems = {"Item1", "Item2 ", "Item3", "Item4"};
    String[] SubItems = {"SubItem1", "SubItem2", "SubItem3", "SubItem4"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListAdapter adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
        setListAdapter(adp);        
    }
}
...