转换的ArrayList<类>字符串[] [英] convert ArrayList<Class> to string[]

查看:134
本文介绍了转换的ArrayList<类>字符串[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类Person

class person{
int ID ;
sting FirstName ;
string Last Name ;
String Telephone ;

}

和我有的ArrayList<人> ;

现在我要显示一个仅包含姓+,+名字的简单列表视图

now I want to display simple list view containing just FirstName + "," + "LastName"

这样我就可以用code像

so I can use code like

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Color Mode");

ListView modeList = new ListView(this);
String[] stringArray = new String[] { "Bright Mode", "Normal Mode" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
modeList.setAdapter(modeAdapter);

builder.setView(modeList);
final Dialog dialog = builder.create();

dialog.show();

所以如何cconvert ArrayList的字符串[]包含格式姓+,+姓氏

我可以循环,但有没有什么好的办法或简单的方法来做到这一点,因为我试图使用适配器,但它没有出现在dialoge

I can loop , but Is there any good way or simple way to do that , because I tried to use adapter but it failed to appear in the dialoge

推荐答案

请您 ArrayAdapter 使用类型而不是字符串(也只是通过了的ArrayList&LT;人&GT; 而不是数组)是这样的:

Make your ArrayAdapter to use the type person and not String (also, just pass the ArrayList<person> instead of an array) like this:

ArrayAdapter<person> modeAdapter = new ArrayAdapter<person>(this, android.R.layout.simple_list_item_1, android.R.id.text1, theArrayList);

然后重写的课的toString 方法:

class person {
        int ID;
        String FirstName;
        String LastName;
        String Telephone;

        @Override
        public String toString() {          
            return "Whatever " + FirstName + " and Whatever  " + LastName;
        }

    }

这篇关于转换的ArrayList&LT;类&GT;字符串[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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