ListActivity值是对象,要显示字符串 [英] ListActivity Values are Objects, Want to Display Strings

查看:131
本文介绍了ListActivity值是对象,要显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个当前显示类型数据的对象列表的ListActivity。这些类型数据对象具有自定义数据:

I have a ListActivity that is currently displaying a list of type Data objects. These type Data objects have custom data:

String title;

下面是我在ListActivity构造:

The following is in my ListActivity constructor:

List<Data> values = dataInterface.getAllData();

ArrayAdapter<Data> adapter = new ArrayAdapter<Data>(this,
    android.R.layout.simple_list_item_1, values);
    setListAdapter(adapter);

屏幕上的应用程序显示所有数据对象没有错误。

The application displays on screen all the Data objects without error.

的问题是,对于每个列表项显示的文本是:

The problem is that the text displayed for each list item is:

Data@42731008
Data@427362c0

等。

我理解这些数据对象的对象ID的。相反,我想以显示Data.title中发现的字符串。我无法弄清楚如何做到这一点。

I understand these are the object id's of the Data objects. Instead, I want to display the Strings found in Data.title. I can't figure out how to accomplish this.

推荐答案

如果你不想使用自定义适配器,然后定义公共字符串的toString()在你的数据类方法如下:

If you don't want to use a custom Adapter, then define the public String toString() method in your Data class as follows:

public String toString {
   return title;
}

它将由一个ArrayAdapter时使用它重新presents在ListView对象

It will be used by the ArrayAdapter when it represents the object in the ListView.

这篇关于ListActivity值是对象,要显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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