新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

ArrayAdapter的定义-创新互联

各种Adapter的用法(适配器)

创新互联建站主营岭东网站建设的网络公司,主营网站建设方案,重庆App定制开发,岭东h5小程序开发搭建,岭东网站营销推广欢迎岭东等地区企业咨询

*同样是一个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
    }    

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


标题名称:ArrayAdapter的定义-创新互联
网页路径:http://www.wjwzjz.com/article/hogde.html
在线咨询
服务热线
服务热线:028-86922220
TOP