java - What kind of adapter should I use to transfer data from a ArrayList to an ListView? -


i trying transfer data database listview. before, using simplecursoradapter transfer data cursor containing data, now, need transfer data 5 lists 5 listviews splitting cursor into. don't think can use arrayadapter because database has multiple columns. i'm not quite sure how create own adapter, though i've read use that. don't know how create own adapter baseadapter.

here fragment layout file

<?xml version="1.0" encoding="utf-8"?>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"               android:orientation="vertical"               android:layout_width="match_parent"               android:layout_height="match_parent">           /* ....(i skipped of irrelevant code here) */      </linearlayout>      <listview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/mainlist"             android:layout_gravity="left|center_vertical"             android:layout_weight="1"/>     <listview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/lunchlist"             android:layout_gravity="left|center_vertical"             android:layout_weight="1"/>     <listview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/dinnerlist"             android:layout_gravity="left|center_vertical"             android:layout_weight="1"/>     <listview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/snacklist"             android:layout_gravity="left|center_vertical"             android:layout_weight="1"/>     <listview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/exerciselist"             android:layout_gravity="left|center_vertical"             android:layout_weight="1"/> </linearlayout> 

code fragment(that i'm using transfer data)

    //append test case database     db.createentry(test);      //simplecursoradapter sequence     cursor = db.getallentries();     string[] = {description, calories, servingsize, date};     int[] = {r.id.description, r.id.calories, r.id.servingsize, r.id.datebox};     adapt = new simplecursoradapter(getactivity(), r.layout.journal_inner_view, cursor,    from, to, 1);     listview listitem = (listview) getactivity().findviewbyid(r.id.mainlist);     listitem.setadapter(adapt);     //to implemented delete , edit commands /*listitem.getonitemlongclicklistener();*/ 

sql create database

db.execsql("create table if not exists " + table_journal + " (_id integer primary key autoincrement, " //non-nls-1$                         + journaldbadapter.meal + " text, " //non-nls-1$                         + journaldbadapter.description + " text, " //non-nls-1$                         + journaldbadapter.date + " text, " //non-nls-1$                         + journaldbadapter.calories + " integer, " //non-nls-1$                         + journaldbadapter.servingsize + " integer" //non-nls-1$                         + " );"); //non-nls-1$ //non-nls-2$); 

i using customadapter extends arrayadapter in app purpose.

check link example.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -