各種Adapter的用法(適配器)
創(chuàng)新互聯(lián)建站主營嶺東網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),嶺東h5小程序開發(fā)搭建,嶺東網(wǎng)站營銷推廣歡迎嶺東等地區(qū)企業(yè)咨詢*同樣是一個ListView,可以用不同的Adapter讓它顯示出來,比如說最常用的ArrayAdapter, SimpleAdapter,BaseAdapter.
android.widget.ArrayAdapter<string> A concrete BaseAdapter that is backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource. However the TextView is referenced, it will be filled with the toString() of each object in the array. You can add lists or arrays of custom objects. Override the toString() method of your objects to determine what text will be displayed for the item in the list. To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.
如何定義ArrayAdapter
錯誤實例:
package com.example.testandroidproject; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ArrayAdapter; public class MainActivity extends ActionBarActivity { private String[] ganlist = new String[]{"孫悟空","豬八戒","沙和尚"}; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); private ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,ganlist); //這樣定義ArrayAdapter會出現(xiàn)紅色錯誤 } }
*****************************************************************************************************
Multiple markers at this line
- Illegal modifier for parameter arrayAdapter; only final is permitted
- Line breakpoint:MainActivity [line: 15] - onCreate(Bundle)
*****************************************************************************************************
正確實例:
package com.example.testandroidproject; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ArrayAdapter; public class MainActivity extends ActionBarActivity { private String[] ganlist = new String[]{"孫悟空","豬八戒","沙和尚"}; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,ganlist); //去掉private } }
另外有需要云服務(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)用場景需求。
本文題目:ArrayAdapter的定義-創(chuàng)新互聯(lián)
新聞來源:http://aaarwkj.com/article14/hogde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、App設(shè)計、網(wǎng)站建設(shè)、云服務(wù)器、品牌網(wǎng)站制作、定制開發(fā)
聲明:本網(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)
猜你還喜歡下面的內(nèi)容