android - Simple display of data from SQlite database -


i trying find simple example of displaying data sqlite database in layout. tried @ "notebook" example has 1 output column. there example out there multiple output columns and, if possible, integer data in of columns?

theblitz,

you may want consider creating own customer adapter. project created custom cursoradapter. result such:

listview custom cursoradapter.

here code custom cursoradapter if use example:

public class itemadapter extends cursoradapter {     private layoutinflater mlayoutinflater;     private context mcontext;     public itemadapter(context context, cursor c) {         super(context, c);         mcontext = context;         mlayoutinflater = layoutinflater.from(context);      }      @override     public view newview(context context, cursor cursor, viewgroup parent) {         view v = mlayoutinflater.inflate(r.layout.items_row, parent, false);         return v;     }      /**      * @author      *       * @param   v      *          view in elements set here displayed.      *       * @param   context      *          running context listview adapter active.      *       * @param   c      *          cursor containing query results display.      */      @override     public void bindview(view v, context context, cursor c) {         string title = c.getstring(c.getcolumnindexorthrow(itemdbadapter.key_title));         string date = c.getstring(c.getcolumnindexorthrow(itemdbadapter.key_date));         string imagepath = c.getstring(c.getcolumnindexorthrow(itemdbadapter.key_img));         string reminder = c.getstring(c.getcolumnindexorthrow(itemdbadapter.key_reminder));         int deletion = c.getint(c.getcolumnindexorthrow(itemdbadapter.key_deletion));         int priority = c.getint(c.getcolumnindexorthrow(itemdbadapter.key_priority));          /**          * next set title of entry.          */          textview title_text = (textview) v.findviewbyid(r.id.item_text);         if (title_text != null) {             title_text.settext(title);         }          setprioritycolor(title_text, priority);          /**          * set date          */          textview date_text = (textview) v.findviewbyid(r.id.item_date);         if (date_text != null) {             date_text.settext(date);         }                 /**          * decide if should display paper clip icon denoting image attachment          */          imageview item_image = (imageview) v.findviewbyid(r.id.item_attachment);         item_image.setvisibility(imageview.invisible);         if (imagepath != null && imagepath.length() != 0 && item_image != null) {             item_image.setvisibility(imageview.visible);         }          /**          * decide if should display deletion indicator          */         imageview del_image = (imageview) v.findviewbyid(r.id.item_deletion);         del_image.setvisibility(imageview.invisible);         if (deletion == 1) {             del_image.setvisibility(imageview.visible);         }          /**          * decide if should display reminder indicator          */         imageview rem_image = (imageview) v.findviewbyid(r.id.item_reminder);         rem_image.setvisibility(imageview.invisible);         if(reminder != null && reminder.length() != 0 && rem_image != null) {             rem_image.setvisibility(imageview.visible);         }     }      /**      * set priority colors based on sharedpreferences      *       * @author      *       * @param   title       *          particular textview item handling      * @param   priority       *          current textview item's associated priority level      */      private void setprioritycolor(textview title, int priority) {         sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(mcontext);         resources res = mcontext.getresources();          switch(priority) {         case itemdbadapter.priority_high:             title.settextcolor(prefs.getint("highcolor", res.getcolor(r.color.high_priority)));             break;         case itemdbadapter.priority_normal:             title.settextcolor(prefs.getint("normcolor", res.getcolor(r.color.norm_priority)));             break;         case itemdbadapter.priority_low:             title.settextcolor(prefs.getint("lowcolor", res.getcolor(r.color.low_priority)));             break;         }     } } 

and xml individual items:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="horizontal"     android:background="@drawable/list_bg">      <linearlayout         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="vertical">          <textview android:id="@+id/item_text"             android:layout_width="200dp"             android:layout_height="wrap_content"             android:lines="1"             android:scrollhorizontally="true"             android:ellipsize="end"             android:paddingleft="2sp"             android:paddingtop="2sp"             android:textsize="18sp"             android:textstyle="bold"             android:shadowcolor="#90909090"             android:shadowdx="1.0"             android:shadowdy="1.0"             android:shadowradius="1.0"/>          <textview android:id="@+id/item_date"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:textsize="12sp"             android:textcolor="#ff808080"             android:paddingleft="2sp"             android:paddingtop="2sp"/>     </linearlayout>      <imageview android:id="@+id/item_deletion"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/deletion"         android:visibility="invisible"         android:layout_centervertical="true"         android:layout_alignparentright="true"         android:paddingright="5sp"/>      <imageview android:id="@+id/item_attachment"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/attachment"         android:visibility="invisible"         android:layout_centervertical="true"         android:layout_toleftof="@id/item_deletion"/>      <imageview android:id="@+id/item_reminder"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/alarm"         android:visibility="invisible"         android:layout_centervertical="true"         android:layout_toleftof="@id/item_attachment"/>  </relativelayout> 

here code main activity: call function display cursor using custom adapter:

private void filldata(string sortorder) {     cursor itemscursor = mdbhelper.fetchallitems(sortorder);     startmanagingcursor(itemscursor);      itemadapter itemadapter = new itemadapter(this, itemscursor);     setlistadapter(itemadapter);     itemadapter = null; } 

the xml main activity: top relative layout action bar

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_height="fill_parent"     android:layout_width="fill_parent"     android:orientation="vertical">      <relativelayout         android:layout_width="fill_parent"         android:layout_height="40dip"         android:background="@drawable/action_bar">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/app_name"             android:textcolor="#ffffff"             android:textsize="20sp"             android:textstyle="bold"             android:shadowcolor="#b0b0b0b0"             android:shadowdx="2.0"             android:shadowdy="2.0"             android:shadowradius="2.0"             android:layout_centervertical="true"             android:paddingleft="10dip"/>          <imageview             android:drawable="@drawable/action_bar_add"             android:id="@+id/action_bar_add"             android:layout_height="fill_parent"             android:layout_width="wrap_content"             android:layout_alignparentright="true"             android:layout_centervertical="true"             android:paddingright="5dip"             android:paddingleft="5dip"             android:src="@drawable/action_bar_add_anim"/>          <view             android:layout_height="fill_parent"             android:layout_width="2px"             android:layout_toleftof="@id/action_bar_add"             android:background="#90909090"/>  </relativelayout>  <linearlayout     android:orientation="horizontal"     android:layout_width="fill_parent"     android:layout_height="fill_parent">      <listview android:id="@id/android:list"         android:layout_width="fill_parent"         android:layout_height="wrap_content"/>      <textview android:id="@+id/android:empty"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:gravity="center"         android:text="@string/no_items"         android:textsize="20sp"         android:textstyle="bold"         android:shadowcolor="#90909090"         android:shadowdx="1.0"         android:shadowdy="1.0"         android:shadowradius="1.0"/>  </linearlayout> </linearlayout> 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -