从一个ArrayList&LT创建微调;对象> [英] Creating a Spinner from an ArrayList<Object>

查看:98
本文介绍了从一个ArrayList&LT创建微调;对象>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我已经创建,因此当选择一个我能回到那个ArrayList和从它那里得到的信息,其余的对象一个ArrayList创建一个微调

I am wanting to create a Spinner from an ArrayList of Objects I have created and therefore when one is selected I can go back to that ArrayList and get the rest of the information from it

示例

public class ObjectName {
    private int ID;
    private String name;
    private String name2;
    public ObjectName{int pID, String pName, String pName2) {
        ID = pID;
        name = pName;
        name2 = pName2;
    }
    //Getters Here
}

的微调code示例

Example of Spinner Code

ArrayList<ObjectName> objects = new ArrayList<ObjectName>;
ArrayAdapter<ObjectName> adapter = new ArrayAdapter<ObjectName>(this, android.R.layout.simple_spinner_item, objects);

当然的微调并没有显示我想要的。有一个简单的方法来解决这个

Of course the Spinner does not show what I want. Is there an easy way to solve this

感谢您的时间

推荐答案

您需要执行的toString 的ObjectName 类。否则微调不知道该怎么表现!

You need to implement toString method inside ObjectName class. Otherwise spinner cannot know what to show!

public String toString() {
    return ID + " " + name + " " + name2;
}

这篇关于从一个ArrayList&LT创建微调;对象&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆