sqlite3 - How do I find the information in a ArrayAdapter of a certain column from a database in Android -
what trying accomplish find out if there information in specific column database returned query. if there information in there going have sound , toast message. query part works fine , information shown in listview way want it. how find out in field? here code query , results:
public void dosearch(view v) { string prefvalue = uihelper.gettext(this, r.id.edittext1); scans = datasource.findfiltered("isbn = " + prefvalue, "isbn asc"); arrayadapter<scan> adapter = new scanlistadapter(this, scans); if (scans.isempty()) { toast.maketext(this, "isbn not found",toast.length_long).show(); mediaplayer mediaplayer = mediaplayer.create(this, r.raw.miss); mediaplayer.start(); } else { setlistadapter(adapter); mediaplayer mediaplayer = mediaplayer.create(this, r.raw.chaching); mediaplayer.start(); scan supply = scans.get(0); log.i(logtag, supply+ " @ index "); if(null == supply) { } else { toast.maketext(this, "requires supply!",toast.length_long).show(); mediaplayer supplyplayer = mediaplayer.create(this, r.raw.meep1); supplyplayer.start(); } } }
here query:
public list<scan> findfiltered(string selection, string orderby) { cursor cursor = database.query(scandbopenhelper.table_scans, allcolumns, selection, null, null, null, orderby); log.i(logtag, "returned " +cursor.getcount() + " rows"); list<scan> scans = cursortolist(cursor); return scans;
}
private list<scan> cursortolist(cursor cursor) { list<scan> scans = new arraylist<scan>(); if (cursor.getcount() >0) { while (cursor.movetonext()) { scan scan = new scan(); scan.setid(cursor.getlong(cursor.getcolumnindex(scandbopenhelper.column_id))); scan.settitle(cursor.getstring(cursor.getcolumnindex(scandbopenhelper.column_title))); scan.setisbn(cursor.getstring(cursor.getcolumnindex(scandbopenhelper.column_isbn))); scan.setauthor(cursor.getstring(cursor.getcolumnindex(scandbopenhelper.column_author))); scan.setprice(cursor.getdouble(cursor.getcolumnindex(scandbopenhelper.column_price))); scan.setieprice(cursor.getdouble(cursor.getcolumnindex(scandbopenhelper.column_ie))); scan.setmaxlimit(cursor.getstring(cursor.getcolumnindex(scandbopenhelper.column_limit))); scan.setsupply(cursor.getstring(cursor.getcolumnindex(scandbopenhelper.column_supply))); scans.add(scan); } } return scans;
the part starts scan supply = scans.get(0) trying find information. sits, want, not using correct field. need information in supply field. suggestions? if not being clear or need more code, please let me know.
how about?
for (scan scan : scans) { string supply = scan.getsupply(); if (supply != null && supply.length() > 0) { toast.maketext(this, "requires supply!",toast.length_long).show(); mediaplayer supplyplayer = mediaplayer.create(this, r.raw.meep1); supplyplayer.start(); } }
Comments
Post a Comment