加入收藏 | 设为首页 | 会员中心 | 我要投稿 江门站长网 (https://www.0750zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Android中ListView与ArrayAdapter配合实施

发布时间:2021-11-25 20:59:11 所属栏目:教程 来源:互联网
导读: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:i
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); 

(编辑:江门站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读