资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ArrayAdapter的定义

各种Adapter的用法(适配器)

创新互联专注于网站设计、成都网站建设、网页设计、网站制作、网站开发。公司秉持“客户至上,用心服务”的宗旨,从客户的利益和观点出发,让客户在网络营销中找到自己的驻足之地。尊重和关怀每一位客户,用严谨的态度对待客户,用专业的服务创造价值,成为客户值得信赖的朋友,为客户解除后顾之忧。

*同样是一个ListView,可以用不同的Adapter让它显示出来,比如说最常用的ArrayAdapter, SimpleAdapter,BaseAdapter.

 android.widget.ArrayAdapter

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的定义


如何定义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 arrayAdapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,ganlist);
        //这样定义ArrayAdapter会出现红色错误
    }    

}

*****************************************************************************************************

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 arrayAdapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,ganlist);
        //去掉private
    }    

}

当前文章:ArrayAdapter的定义
网页URL:http://cdkjz.cn/article/jjpogi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220