Android學(xué)習(xí)--ListView的使用(二)

 基于ArrayAdapter 創(chuàng)建ListView

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供墨江網(wǎng)站建設(shè)、墨江做網(wǎng)站、墨江網(wǎng)站設(shè)計(jì)、墨江網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、墨江企業(yè)網(wǎng)站模板建站服務(wù),十余年墨江做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

程序清單

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);
        //定義一個數(shù)組
        String arr[]={"??峋W(wǎng)絡(luò)1","??峋W(wǎng)絡(luò)2","??峋W(wǎng)絡(luò)3","??峋W(wǎng)絡(luò)4","??峋W(wǎng)絡(luò)5"};
        //將數(shù)組包裝成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 學(xué)習(xí)--ListView 的使用(二)

本文名稱:Android學(xué)習(xí)--ListView的使用(二)
網(wǎng)站網(wǎng)址:http://www.muchs.cn/article38/ipppsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、靜態(tài)網(wǎng)站、微信小程序、營銷型網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司