android - Show data in listview from airport -
i doing project want display list of airports in listview. airports names retrieved local database. data database in sqliteopenhelper class
public list<airportlist> getallairportlists() { list<airportlist> airportlist = new arraylist<airportlist>(); string selectquery = "select * " + table_airport; log.i("query", selectquery); sqlitedatabase db = this.getwritabledatabase(); cursor cursor = db.rawquery(selectquery, null); if(cursor.movetofirst()) { do{ airportlist airport = new airportlist(); airport.setid(integer.parseint(cursor.getstring(0))); airport.setname(cursor.getstring(1)); }while(cursor.movetonext()); } return airportlist; }
and iam new android can 1 please give idea call method in main class , show airport list in listview.
first of in method above need add airport objects in "airportlist" like:
`public list getallairportlists() {
list<airportlist> airportlist = new arraylist<airportlist>(); string selectquery = "select * " + table_airport; log.i("query", selectquery); sqlitedatabase db = this.getwritabledatabase(); cursor cursor = db.rawquery(selectquery, null); if(cursor.movetofirst()) { do{ airportlist airport = new airportlist(); airport.setid(integer.parseint(cursor.getstring(0))); airport.setname(cursor.getstring(1)); airportlist.add(airport); }while(cursor.movetonext()); } return airportlist;
}`
then assign list in listview in main class. like:
listview = (listview) findviewbyid(r.id.listview); listview.setadapter(new appadapter(airportlist));
class appadapter extends arrayadapter<airportlist> { appadapter(list<airportlist> itemlist) { super(youracitivity.this, r.layout.airport_item_list, itemlist); } @override public view getview(int position, view convertview, viewgroup parent) { if (null == convertview) { convertview = newview(parent); } bindview(position, convertview); return convertview; } private view newview(viewgroup parent) { return getlayoutinflater().inflate(r.layout.airport_item_list, parent, false); } private void bindview(int position, view row) { } }
Comments
Post a Comment