成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

安卓開發(fā)之BaseAdapter用法舉例,創(chuàng)建圖形文字混合列表項-創(chuàng)新互聯(lián)

baseAdapter的用法
   1.創(chuàng)建一個數(shù)組資源類GeneralBean

公司主營業(yè)務(wù):成都網(wǎng)站設(shè)計、做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)公司推出寶清免費做網(wǎng)站回饋大家。

        package com.example.hoyin0211.entry;

public class GeneralBean {
   private int resid;
   private String name;
   @Override
   public String toString() {
      return "GeneralBean [resid=" + resid + ", name=" + name + "]";
   }
   public GeneralBean(int resid, String name) {
      super();
      this.resid = resid;
      this.name = name;
   }
   public int getResid() {
      return resid;
   }
   public void setResid(int resid) {
      this.resid = resid;
   }
   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }

}

   2.定義字符串?dāng)?shù)組資源string-array

          <string-array name="city">
       <item name="bj">北京</item>
       <item name="sh">上海</item>
       <item name="sz">深圳</item>
       <item name="gz">廣州</item>
       <item name="wh">武漢</item>
       <item name="xa">西安</item>
       <item name="hb">嘻嘻哈哈</item>
   </string-array>

   3.定義列表橫向布局(ImageView,TextView)

        <?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="wrap_content"
   android:orientation="horizontal" >

   <ImageView
       android:id="@+id/ivThumb"
       android:contentDescription="chenyi"
       android:layout_width="80dp"
       android:layout_height="80dp"
       android:src="@drawable/chenyi"/>
   <TextView
       android:id="@+id/tvName"
       android:layout_width="wrap_content"
       android:layout_height="80dp"
       android:layout_marginLeft="10dp"
       android:text="陳毅"
       android:textSize="20sp"
       android:gravity="center_vertical" />

</LinearLayout>

   4.在主布局中添加listview

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

   <ListView
       android:id="@+id/mlvTest"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:divider="#ccc"
       android:dividerHeight="2dp"/>

</LinearLayout>

   5.定義listview,集合,GeneralAdapter,圖片資源數(shù)組變量
      ListView listview;
      List<GeneralBean> mGeneralBeans;
      GeneralAdapter mAdapter;
      int[] resid = {R.drawable.zhude,R.drawable.....};
   6.將資源中的字符串?dāng)?shù)組轉(zhuǎn)換成java中的字符串?dāng)?shù)組
      private void initData(){
         String[] names=getResources().getStringArray(R.array.city);
         mGenerals = new ArrayList<GeneralBean>();
         for(int i = 0 ; i < names.length; i++){
            GeneralBean bean = new GeneralBean(Resid[i],names[i]);
            mGenerals.add(bean);
         }
      }
   7.創(chuàng)建BaseAdapter適配器
      class GeneralAdapter extends BaseAdapter{
         public int getCount(){
            retuen mGenerals.size();
         }

         public GeneralBean getItem(int position){
            return mGenerals.get(position);
         }

         public long getItemId(int position){
            return position;
         }

         public View getView(int position,View convertView,ViewGroup parent){
            //拿到listviewitem布局,轉(zhuǎn)換成view類型的對象
            View layout = View.inflate(MainActivity.this,R.layout.item_general,null);
            //找到p_w_picpathview
            ImageView ivThube = (ImageView) layout.findViewById(R.id.ivThumb);
            TextView tvName = (TextView) layout.findViewById(R.id.tvName);
            //獲取下標(biāo)為position的圖片
            GeneralBean bean = mGenerals.get(position);
            //顯示圖片
            ivThumb.setImageResource(bean.getResid());
            //顯示姓名
            tvName.setText(bean.getName());
            return layout;
         }
      }

   8.關(guān)聯(lián)適配器
      listview = (ListView) findViewById(R.id.mlvTest);
      mAdapter = new GeneralAdapter();
      listview.setAdapter(mAdapter);

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站欄目:安卓開發(fā)之BaseAdapter用法舉例,創(chuàng)建圖形文字混合列表項-創(chuàng)新互聯(lián)
新聞來源:http://jinyejixie.com/article24/digece.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、App設(shè)計、網(wǎng)站收錄、自適應(yīng)網(wǎng)站、網(wǎng)站營銷、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quá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è)計公司
昌都县| 克东县| 深圳市| 江门市| 南开区| 晋江市| 定州市| 临朐县| 万山特区| 沛县| 桂阳县| 普定县| 昭觉县| 财经| 民和| 平定县| 石家庄市| 满城县| 江源县| 金华市| 连云港市| 高淳县| 图片| 屯门区| 临沭县| 额尔古纳市| 闵行区| 宁强县| 井冈山市| 密云县| 巫山县| 高阳县| 蒲江县| 九台市| 彭山县| 鄂尔多斯市| 周至县| 千阳县| 凌海市| 额尔古纳市| 济宁市|