ListViw详解笔记

在Android开发中,ListViw的使用是非常多的,下面列举ListView的一些使用方法

显示ListView列表时,必需要三个元素:

1、ListView对象,用来显示具体的数据。

2、Adapter适配器,用将要显示的数据映射到ListView上。

  可用:ArrayAdapter(一般只显示一行文字时用)、SimpleAdapter(可扩展性强)、SimpleCursorAdapter(用于显示数据库的数据)

3、ListView要显示的数据,包括:字符串,图片,控件等。

一、ArrayAdapter:展示数组列表,一般只需要展示一行文字的时候可用这个,

ListViw详解笔记

源代码:

显示ArrayAdapter源码
   
     
public class ClassView1 extends Activity {
private ListView lvListView;

protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
lvListView
= new ListView( this );
lvListView.setAdapter(
new ArrayAdapter < String > ( this ,
android.R.layout.expandable_list_content, getData()));
setContentView(lvListView);
}

private List < String > getData() {
List
< String > list = new ArrayList < String > ();
list.add(
" 中华人民共和国 " );
list.add(
" 广东省 " );
list.add(
" 海南省 " );
list.add(
" 湖南省 " );
list.add(
" 湖北省 " );
list.add(
" 福建省 " );
list.add(
" 北京市 " );
return list;
}
}

你可能感兴趣的:(list)