java - SugarOrm data display junk -
when display data display junk data use listview display data.
public class mainactivity extends actionbaractivity { button btnsave, btndelete; edittext title, edition; listview mlistview; arrayadapter<book> adapter; book book = new book(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); 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); mlistview.setadapter(adapter); toast.maketext(getapplicationcontext(), "" + list, toast.length_long).show(); btnsave.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { book = new book(title.gettext().tostring(), edition.gettext().tostring()); book.save(); toast.maketext(getapplicationcontext(), "" + book, toast.length_long).show(); } }); btndelete.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { book book = book.findbyid(book.class, (long) 1); book.delete(); } }); } }
book.java
public class book extends sugarrecord<book>{ string title; string edition; public book() { } public book(string title,string edition) { this.title=title; this.edition=edition; } }
when delete data delete when display display junk data how can display proper data?
you need create custom adapter render values book object. simplest option implement tostring() method in book class. should fix that.
Comments
Post a Comment