1

I am getting the value from my parse db in list view. But the problem is I am not being able to structured the output. e.g When i calling the parse class i am getting output as enter image description here

Whereas i need something like

john

1A Camac Street

123456789

[email protected]

All as one list item then another name and details and so on.

I am using code:

ParseQuery query = ParseQuery.getQuery("Stage1");
 query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> objects, ParseException error) {
                if (error == null) {

                    ArrayList<String> arraystage = new ArrayList<String>();
                    for (ParseObject j : objects) {

                        arraystage.add(j.getString("Name"));
                        arraystage.add(j.getString("Address"));
                        arraystage.add(j.getString("Phone"));
                        arraystage.add(j.getString("Email"));
                        //arraystage.subList(1,4);
                    }

                    ArrayAdapter adapter = new ArrayAdapter(Userprofile_view.this, android.R.layout.simple_list_item_1, arraystage);
                    lvdet.setAdapter(adapter);
                }
            }
        });

So any one can help me.

1
  • You should read about custom adapters for ListView. In particular, Parse provides an implementation that works seamlessly with Parse. Commented Mar 25, 2017 at 10:09

2 Answers 2

1

For such a list, you can't use simple_list_item. You need to create a custom view and override the getView method. Checkout this post http://www.survivingwithandroid.com/2012/10/android-listview-custom-adapter-and.html

I also think it would make thing easier if you use an Contact object that you populate with data from parse object

class Contact{
   String name, address, phone, email;
}

And the adapter

    ArrayList<Contact> arraystage = new ArrayList<Contact>();

                for (ParseObject j : objects) {

                       Contact c = new Contact();

                       c.name = j.getString("Name");
                       c.address = j.getString("Address");
                       c.phone = j.getString("Phone");
                       c.email = j.getString("Email");
                       arraystage.add(c);
                 }

    ArrayAdapter adapter = new ArrayAdapter(Userprofile_view.this, android.R.layout.your_custom_view, arraystage){
        public View getView(int position, View convertView, ViewGroup parent) {

        }
   };

lvdet.setAdapter(adapter);
Sign up to request clarification or add additional context in comments.

4 Comments

@Code-Apprentice that depends on the view hierarchy of the custom view
I deleted my comment because I was confused with SimpleCursorAdapter which has a constructor where you can provide the mapping from columns to view ids in the row.
Would class Contact extends ParseObject complicate your answer too much?
@Code-Apprentice Again it depends. If it's documented to be extensible then it wouldn't complicate things
1

By default ArrayAdapter uses item's toString() to get the item text.

If you need something else you have to override ArrayAdapter.getView()

1 Comment

>In your case arraystage.toString().............That doesn't sound right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.