简体   繁体   中英

ParseObject Subclass to simple ListView

I'm trying to create a simple list view from a list of ParseObjects . The issue is the toString method doesn't seem to be overriding the super class, so I'm just getting the class name displayed (eg, com.parse.ParseObject@416161e8) in the list view. I've created this exact setup before without using a ParseObject and it works how I'd expect. Am I just missing something simple?

My class that extends ParseObject

@ParseClassName("Foo")
public class Foo extends ParseObject {
    public String getName(){
        return getString("name");
    }
    public void setName(String name){
        put("name", name);
    }

    public String getType(){
        return getString("type");
    }
    public void setType(String type){
        put("type", type);
    }

    @Override
    public String toString() {
        return getName();
    }
}

My code that sets the listview adapter.

    ParseQuery<Foo> query = ParseQuery.getQuery(Foo.class);
    query.findInBackground(new FindCallback<Foo>() {
        public void done(List<Foo> foos, ParseException e) {
            if (e == null) {
                listView.setAdapter(new ArrayAdapter<Foo>(context, android.R.layout.simple_list_item_1, foos));
            } else {

            }
        }
    });

Ugh, I missed in the docs about registering the sub class.

Place ParseObject.registerSubclass(YOURSUBLCASS.class); before Parse.initialize(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM