javaandroidstringparse-platformparse-android-sdk

Android parse: Get strings from parsequeryadapter and store them into an ArrayList


I have a ParseQueryAdapter class, and my items are being retrieved successfully. However, if I have this for loop to view the objects (strings):

 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. Why is this? It is supposed to be:

listItem1
listItem2
listItem3

Thanks in advance


Solution

  • 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.

    If you own this type, simply @Override the toString() method with your own implementation.

    Example:

    Assuming your type name is YourType. I mean, adapter.getItem(i) returns an object of YourType. In YourType.java:

    class YourType {
        private String exampleField1;
        private String exampleField2;
    
        @Override
        public String toString() {
            return exampleField1 + ", " + exampleField2;
        }
    }