The use of Android's custom Simplecursoradapter

Source: Internet
Author: User

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.