View Code
1
2 3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 >
7 8 android:layout_height="wrap_content"
9 android:text="@string/tv1"
10 android:background="#FFF"
11 android:textColor="#888"
12 android:gravity="center"/>
13 14 android:layout_width="fill_parent"
15 android:layout_height="wrap_content"/>
16
17 18 android:layout_height="wrap_content"
19 android:text="@string/tv2"
20 android:background="#FFF"
21 android:textColor="#888"
22 android:gravity="center"/>
23 24 android:layout_width="fill_parent"
25 android:layout_height="wrap_content"/>
26
27 28 android:layout_height="wrap_content"
29 android:text="@string/tv3"
30 android:background="#FFF"
31 android:textColor="#888"
32 android:gravity="center"/>
33 34 android:layout_width="fill_parent"
35 android:layout_height="wrap_content"/>
36
37
View Code
1
2
3 Hello World, Listview02Activity!
4 Listview02
5 单项打勾
6 RadioButton
7 CheckBox
8
View Code
1 package cn.shaoyangjiang.com;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.widget.ArrayAdapter;
6 import android.widget.ListView;
7
8 public class Listview02Activity extends Activity {
9 /** Called when the activity is first created. */
10 @Override
11 public void onCreate(Bundle savedInstanceState) {
12 super.onCreate(savedInstanceState);
13 setContentView(R.layout.main);
14 //得到三个listview
15 ListView listview1 = (ListView)findViewById(R.id.lvCheckedTextView);
16 ListView listview2 = (ListView)findViewById(R.id.lvRadioButton);
17 ListView listview3 = (ListView)findViewById(R.id.lvCheckedButton);
18 //用string来保存listview要显示的数据
19 String[] data = new String[]
20 {"邵洋江加油","你会成功的"};
21 //构建适配器Adapter,将数据与显示数据的布局页面绑定;
22 ArrayAdapter lv1Adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_checked,data);
23 //通过setAdapter()方法把适配器设置给ListView
24 listview1.setAdapter(lv1Adapter);
25 //listview里的内容设置为单选
26 listview1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
27
28 ArrayAdapter lv2Adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice,data);
29 listview2.setAdapter(lv2Adapter);
30 listview2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
31
32 ArrayAdapter lv3Adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_multiple_choice,data);
33 listview3.setAdapter(lv3Adapter);
34 listview3.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
35 }
36 }