为什么listView没有正确显示我的对象?

时间:2015-08-27 17:54:45

标签: android listview

我有一个JSONArray,我想将所有对象添加到listView作为学校作业的一部分。

当我现在得到代码时,listView显示对象的引用,但不显示字符串: Print screen

我在gitHub中有代码:

https://github.com/tomasfly/ejercicioFinalLottery

我创建了3个包(模型,视图,控制器),在我的mainActivy中,我有一个从AsyncTask扩展的类,并且有一个onPostExecute()方法:

ExpiredTokenException

2 个答案:

答案 0 :(得分:1)

好的,看看你的代码和你的评论很容易看出你正在传递一个对象并且它只是对对象的一个​​串联。为什么不将你想要在对象中显示的任何字符串提取到另一个字符串数组中呢。

答案 1 :(得分:1)

您可以简单地覆盖Jugadas模型中的toString()

否则,您需要覆盖适配器中的getView()并从那里填充文本。

adapter = new ArrayAdapter<Jugadas>(this,android.R.layout.simple_list_item_1, arrayOfData){
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = mInflater.inflate(R.layout.list_item_vehicle_info, parent, false);
        } else {
            view = convertView;
        }

        final TextView text= (TextView) view.findViewById(android.R.id.text1);

        final Jugadas item = getItem(position);
        text.setText(item.name()); 
        //item.name() above is just an example. you will do whatever you need to get the string you want from your data instance.
        return view;
    }
}