首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将countries[ ]改为ArrayList<<Post>> android

将countries[ ]改为ArrayList<<Post>> android
EN

Stack Overflow用户
提问于 2013-04-12 15:33:35
回答 1查看 78关注 0票数 0

在我的应用程序中,我尝试使用setter和getter方法填充轮子适配器,如我的Post类中所示。

类Post {

代码语言:javascript
复制
   private String imageList;
   private String country_name;
   private String country_code;

  public void setImageList (    String imageList){
        this.imageList = imageList;
    }

  public String getImageList (){
        return imageList;
    }


 public void setCountryName (   String country_name){
        this.country_name = country_name;
    }

  public String getCountryName (){
        return country_name;
    }
...


}

我的wheelAdapter类如下所示:

代码语言:javascript
复制
public class SecondWheelAdapter extends AbstractWheelTextAdapter {

    ArrayList<convertor_pst> PostList = new ArrayList<convertor_pst>();

    public ImageLoader imageLoader; 

    // Countries names
    private String countries[] =
            new String[] {"EUR", "USD","EUR", "USD","EUR", "USD","EUR", "USD","EUR", "USD","EUR", "USD"};

    // Countries flags
    private int flags[] = new int[] {R.drawable.eur, R.drawable.usd,R.drawable.eur, R.drawable.usd,R.drawable.eur, R.drawable.usd,R.drawable.eur, R.drawable.usd,R.drawable.eur, R.drawable.usd,R.drawable.eur, R.drawable.usd};

    /**
     * Constructor
     */


    Convertor main;

    public SecondWheelAdapter(Context context) {
        super(context, R.layout.country_layout, NO_RESOURCE);
        setItemTextResource(R.id.country_name);
    }

    @Override
    public View getItem(int index, View cachedView, ViewGroup parent) {

        View view = super.getItem(index, cachedView, parent);
        ImageView img = (ImageView) view.findViewById(R.id.flag);
        img.setImageResource(flags[index]);

        return view;
    }

    @Override
    public int getItemsCount() {
        return countries.length;
    }


    @Override
    protected CharSequence getItemText(int index) {
        return countries[index];
    }

我正在尝试替换这个数组

代码语言:javascript
复制
// Countries names
        private String countries[] =
                new String[] {"EUR", "USD","EUR", "USD","EUR", "USD","EUR", "USD","EUR", "USD","EUR", "USD"};

请给我一个提示或教程来遵循。我从github得到了这个轮子适配器,它附带了一个库,但我遇到了困难。

EN

回答 1

Stack Overflow用户

发布于 2013-04-12 15:38:29

优化的解决方案:

我建议您创建一个ArrayList,而不是管理不同的字符串数组或ArrayList,这样管理单个ArrayList会更容易。

我的意思是删除countries[]flags[]并创建单一的ArrayList<Post>类型。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15965597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档