Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 操作系统 / Linux / Android中ListView与ArrayAdapter配合使用

1、配置布局文件: <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <!--  注意这里的android:id是使用内置的-->
    <ListView    android:id="@android:id/list "
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"></ListView>
       
</LinearLayout> 2、Java代码 protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String[]items ={"aaa","bbbb","cccc"};
        ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1 ,items);
        setListAdapter(arrayAdapter); 3、显示效果如下: