ListView中的Item和SubItem

时间:2011-12-20 13:15:15

标签: android android-layout android-arrayadapter listadapter

我想使用Arrayadapter和android.R.layout.simple_list_item_2在列表视图中显示Item和相应的子项。我可以列出包含以下代码的项目

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);        
    }
}

0 个答案:

没有答案