Artsait Artsait - 1 month ago 16x
Android Question

How to return all data from one column sugar orm

How to return all data from one column sugar orm ?

import com.orm.SugarRecord;
import java.util.List;

public class Contact extends SugarRecord{
String name;
String mail;
public Contact() {
public Contact(String name, String mail) { = name;
this.mail = mail;


List<Contact> allContacts = Contact.listAll(Contact.class);

ArrayAdapter<Contact> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,, allContacts);
ListView catsListView = (ListView) findViewById(;

How can I Load the name column in the array?


Looking at the source code of the ArrayAdapter you can't do that.

Either you need to form a new ArrayList<String> as follows and pass it to ArrayAdapter.

ArrayList<String> arr = new ArrayList<>();
for(Contact contact:allContacts){
    arr.add(contact.getName()); // or arr.add(; if it's public

Or you need to define customAdapter extending ArrayAdapter