1、Listview简述
A view that shows items in a vertically scrolling list. The items come from theListAdapter
associated with this view.
简单来说就是,创建Listview,然后给数值就行了。
而这些数值来源有三种方式:ArrayAdapter、SimpleAdapter、SimpleCursorAdapter
第一种是最简单的一种Adapter,是字符串数值,只能在ListView显示出文本信息。
第二种是一种自定义的数据来源,要自定义布局方式,可以放置图片,按钮,文本之类的。
第三种数据来源于数据库。
2、使用ListView步骤
将数据填充到布局之ArrayAdapter的使用
布局文件加入ListView控件:
<ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" />
主程序:
MyListView.java package com.ycz.mylistview; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends Activity{ private static final String[] str=new String[]{"first","second","third","fourth","fifth"}; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); lv=(ListView)findViewById(R.id.lv); //绑定ArrayAdapter适配器 lv.setAdapter(new ArrayAdapter<String>(t