Simplecursoradapter methods for direct use:
Simplecursoradapter allows you to bind a cursor column to ListView and use the custom Layout displays each item.
Simplecursoradapterneed to pass in the current context, aLayoutresource, a cursor, and two arrays: one containing the name of the column used, and the other (same size) array containingViewthe resources inIDTo display the data values for the corresponding columns.
First step: Read data from the database DBHelper = new DBHelper (historyorderactivity.this);d atabase = Dbhelper.getwritabledatabase (); cursor = Database.rawquery ("SELECT * from" +dbhelper.table_order+ "where feedbacktime are NOT NULL", NULL);//startmanagingcursor ( cursor); The method of abandonment is to leave the cursor's life cycle to the activity management string[] Fromcolumns = new string[] {"Orderdescription", "Ordereffectivetime", " Orderconsumetime "," Promotion "," Feedbackinfo "," Feedbacktime ",};int[] tolayoutids = new int[] {r.id.description, R.id.effectivetime, R.id.consumetime, r.id.promotion,r.id.feedbackinfo, r.id.feedbacktime};adapter = new Simplecursoradapter (this, r.layout.histortyorder, cursor, fromcolumns, tolayoutids,0);
simplecursoradapter Use of custom:
First step: Read data from the database DBHelper = new DBHelper (historyorderactivity.this);d atabase = Dbhelper.getwritabledatabase (); cursor = Database.rawquery ("SELECT * from" +dbhelper.table_order+ "where feedbacktime are NOT NULL", NULL);//startmanagingcursor ( cursor); The method of abandonment is to leave the cursor's life cycle to the activity management string[] Fromcolumns = new string[] {"Orderdescription", "Ordereffectivetime", " Orderconsumetime "," Promotion "," Feedbackinfo "," Feedbacktime ",};int[] tolayoutids = new int[] {r.id.description, R.id.effectivetime, R.id.consumetime, R.id.promotion,r.id.feedbackinfo, r.id.feedbacktime};if (cursor = = NULL) { return;} adapter = new Historyorderadapter (Historyorderactivity.this, R.layout.histortyorder,cursor, Fromcolumns, ToLayoutIDs , 0);
Implementation of the adapter:
public class Historyorderadapter extends Simplecursoradapter {private Cursor m_cursor;private Context m_context;private Layoutinflater Miinflater;public Historyorderadapter (context context, int layout, Cursor c,string[] from, int[] to, int fl AGS) {Super (context, layout, C, from, to, flags); m_context = Context;m_cursor = C;} @Overridepublic void BindView (View arg0, Context arg1, Cursor arg2) {View Convertview = null;if (arg0 = = null) {Convertvie W = miinflater.inflate (R.layout.histortyorder, null);} else {convertview = arg0;} TextView tv_description = (TextView) Convertview.findviewbyid (r.id.description); TextView tv_effectivetime = (TextView) Convertview.findviewbyid (r.id.effectivetime); TextView tv_consumetime = (TextView) Convertview.findviewbyid (r.id.consumetime); TextView tv_promotion = (TextView) Convertview.findviewbyid (r.id.promotion); TextView Tv_feedbackinfo = (TextView) Convertview.findviewbyid (r.id.feedbackinfo); TextView tv_feedbacktime = (TextView) Convertview.findviewbyid (r.id.feEdbacktime); Tv_description.settext (Arg2.getstring (Arg2.getcolumnindex ("orderdescription")); tv_ Effectivetime.settext (Shoputils.changetimestamptotime (long.valueof (arg2.getstring (Arg2.getColumnIndex (" Ordereffectivetime "))), Tv_consumetime.settext (Shoputils.changetimestamptotime (long.valueof (arg2.getString ( Arg2.getcolumnindex ("Orderconsumetime")))), Tv_promotion.settext (Arg2.getstring (Arg2.getcolumnindex ("Promotion ")); Tv_feedbackinfo.settext (Arg2.getstring (Arg2.getcolumnindex (" Feedbackinfo ")); Tv_feedbacktime.settext ( Shoputils.changetimestamptotime (Long.valueof (arg2.getstring (Arg2.getcolumnindex ("FeedbackTime"))));}}
Historyorderadapter is a bit rough and needs to be improved.