JATIN DEVANI JATIN DEVANI - 10 months ago 55
Android Question

SugarOrm data display junk

when I display the data that display junk data I use listview to display the data.

public class MainActivity extends ActionBarActivity {

Button btnSave, btnDelete;
EditText title, edition;
ListView mListView;
ArrayAdapter<Book> adapter;

Book book = new Book();

protected void onCreate(Bundle savedInstanceState) {

title = (EditText) findViewById(R.id.editTextTitle);
edition = (EditText) findViewById(R.id.editTextEdition);

btnSave = (Button) findViewById(R.id.buttonSave);
btnDelete = (Button) findViewById(R.id.buttonDelete);

mListView = (ListView) findViewById(R.id.listView);

// List<Book> list= Select.from(Book.class).list();
List<Book> list = Book.listAll(Book.class);

adapter = new ArrayAdapter<Book>(MainActivity.this, android.R.layout.simple_list_item_1, list);

Toast.makeText(getApplicationContext(), "" + list, Toast.LENGTH_LONG).show();

btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

book = new Book(title.getText().toString(), edition.getText().toString());

Toast.makeText(getApplicationContext(), "" + book, Toast.LENGTH_LONG).show();

btnDelete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

Book book = Book.findById(Book.class, (long) 1);




public class Book extends SugarRecord<Book>{

String title;
String Edition;

public Book()

public Book(String title,String Edition)

when I delete the data than it delete also but when display it display junk data how can I display proper data?

Answer Source

You need to create a custom adapter to render values from your book object. Simplest option would be to implement the toString() method in the Book class. That should fix that.