[英]Android parse: Get strings from parsequeryadapter and store them into an ArrayList
I have a ParseQueryAdapter class, and my items are being retrieved successfully.我有一个 ParseQueryAdapter 类,我的项目正在成功检索。 However, if I have this for loop to view the objects (strings):
但是,如果我有这个 for 循环来查看对象(字符串):
for (int i =0;i<adapter.getCount();i++){
Log.d("Ab", adapter.getItem(i).toString());
}
I get these:我得到这些:
com.example.ab_me.example.classname@41ef11f8
com.example.ab_me.example.classname@41ef33d8
com.example.ab_me.example.classname@41ef40c0
Note : For security reasons, I replaced my app name with example
and my classname with classname
.注意:出于安全原因,我用
example
替换了我的应用程序名称,用classname
替换了我的classname
。 Why is this?为什么是这样? It is supposed to be:
它应该是:
listItem1
listItem2
listItem3
Thanks in advance提前致谢
The Object
that is returned from getItem
method call does not override toString()
method, so java uses a default implementation in this case because it doesn't 'know' how to convert the object to a String
type.从
getItem
方法调用返回的Object
不会覆盖toString()
方法,因此在这种情况下 java 使用默认实现,因为它不“知道”如何将对象转换为String
类型。
If you own this type, simply @Override
the toString()
method with your own implementation.如果您拥有此类型,只需使用您自己的实现
@Override
toString()
方法。
Example :示例:
Assuming your type name is YourType
.假设您的类型名称是
YourType
。 I mean, adapter.getItem(i)
returns an object of YourType
.我的意思是,
adapter.getItem(i)
返回一个YourType
对象。 In YourType.java
:在
YourType.java
:
class YourType {
private String exampleField1;
private String exampleField2;
@Override
public String toString() {
return exampleField1 + ", " + exampleField2;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.