简体   繁体   English

Android parse:从 parsequeryadapter 中获取字符串并将它们存储到一个 ArrayList 中

[英]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.

相关问题 从文件中读取一个数组列表,然后将数组列表分成多个字符串,这样我就可以分别解析它们 - Reading in from a file into an arraylist then dividing array list into multiple strings so I can parse them individually 从类获取值并将其存储在ArrayList中 - Getting Values from a class & store them in an ArrayList 从解析对象获取ArrayList - get ArrayList from Parse Object 如何从ArrayList获取String值并将它们存储在Java 8中用逗号分隔的单个字符串中? - How to get String values from ArrayList and store them in a single string separated by commas, in Java 8? 如何使用Java Play中的MorphiaQuery从集合中获取所有_id值并将其存储在arraylist中 - How to get all _id values from a collection and store them in arraylist using MorphiaQuery in Java Play 如何从 String 中过滤掉 Unique 元素并将它们存储到 ArrayList - How filter out Unique elements from a String and store them into an ArrayList 从文件中读取元素,并将其作为对象存储在ArrayList中 - Read elements from a file and store them in ArrayList as Objects 如何将 ArrayList<>() 中的字符串解析为 Map<string, string></string,> - How to Parse Strings from an ArrayList<>() into a Map<String, String> Android Studio - 如何从 RecyclerView 中的 EditText 获取数据并将它们放入主要活动中的 ArrayList? - Android Studio - How to get data from an EditText in a RecyclerView and put them into an ArrayList in the main activity? 如何从 arraylist 中获取整数,使用它们进行计算并打印它们 - how to get integers from an arraylist, use them for calculations and print them
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM