How to return all data from one column sugar orm ?
Contact.java
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) {
this.name = name;
this.mail = mail;
}
}
MainActivity.java
List<Contact> allContacts = Contact.listAll(Contact.class);
ArrayAdapter<Contact> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
android.R.id.text1, allContacts);
ListView catsListView = (ListView) findViewById(R.id.listView);
catsListView.setAdapter(adapter);
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(contact.name); if it's public
}
Or you need to define customAdapter
extending ArrayAdapter
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.