码迷,mamicode.com
首页 > 移动开发 > 详细

Android 学习--ListView 的使用(二)

时间:2015-03-14 20:15:58      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:android

 基于ArrayAdapter 创建ListView

程序清单


listview2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/list1"
        android:divider="#0f0"
        android:dividerHeight="3px"
        android:footerDividersEnabled="false"
         />
</LinearLayout>

MainActivity.java

package xiaocool.net.listviewtest;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class MainActivity extends ActionBarActivity {

   private ListView list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview2);
        list=(ListView)this.findViewById(R.id.list1);
        //定义一个数组
        String arr[]={"校酷网络1","校酷网络2","校酷网络3","校酷网络4","校酷网络5"};
        //将数组包装成ArrayAdapter
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.array_item,R.id.textView,arr);
        list.setAdapter(adapter);

    }



}

array_item..xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:textSize="20sp"
        android:textColor="#f0f"
        android:padding="20px"
        />
</LinearLayout>

技术分享

Android 学习--ListView 的使用(二)

标签:android

原文地址:http://xiaocool.blog.51cto.com/1593956/1620313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!