Android小筆記

來源:互聯網
上載者:User

標籤:一天小摘要

        ListView是一個資料控制項,可以可以展示從資料庫中讀取的資料,用TextView來實現輸出。


        ImageView是用於顯示圖片的一個控制項,可以擷取到資料庫中的圖片來顯示輸出。


        ArrayAdapter文本適配器:擷取到集合、數組中的資料值,再尤通過載入適配器來擷取到適配器中的內容來輸出。實現ArrayAdapter適配器的方法:

        //先建立一個數組

        private String[] ctype = new String[]{"內容1","內容2","內容3"};

        //通過文本適配器擷取到數組中的值

        ArrayAdapter<String> adater = 

                    new ArrayAdapter<String> (this,android.R.id.simple_spinner_item,ctype);

        //為適配器設定列表框下拉時的選項樣式

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        //載入適配器擷取結果

        spinner.setAdapter(adapter);


        simpleAdapter圖文適配器:用於圖片和文字的匹配對應關係。

        //先建立一個用於存放文字的數組和一個存放圖片的數組

        private String[] ctype = new String[]{"內容1","內容2","內容3"};

        private int img = new int[]{R.drawable.logo,R.drawable.logo,R.drawable.logo,};

        //圖文適配器

        List<Map<String,object>> datas = new ArrayList<Map<String,object>>();

        for(int i = 0;i<object<length;i++){

            Map<String,object> map = new Map<String,object>();

            map.put("image",img[i]);

            map.put("name",ctype[i]);

            datas.add(map);

        }

        SimpleAdapter adapter = new SimpleAdapter(this,datas,R.layout.list_item,

                        new String[]{"image","name"},new int[]{R.id.iv_logo,R.id.tv_name});

        //載入適配器

        lv.setAdapter(adapter);

        還有個自定適配器沒弄過,明天繼續!650) this.width=650;" src="http://img.baidu.com/hi/bobo/B_0054.gif" alt="B_0054.gif" />

本文出自 “Android小筆記” 部落格,請務必保留此出處http://dreamwing.blog.51cto.com/9872128/1609817

Android小筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.