facing difficulties in getting contacts in listview - android

I am trying to get all the contacts of the phone in a listview with checkboxes in order to select multiple contacts at a time. I have written some code which is creating the same number of rows as the number of contacts in my emulator. But the problem is the name and number of the contacts are not appearing as you can see in the image attached. Moreover when i click Show contacts button to show the selected contacts in Toast that too is not happening.
custcontactview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="5.0px"
android:paddingLeft="5.0px"
android:paddingTop="5.0px" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/cConName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/checkBox1"
android:layout_marginLeft="15.0dip"
android:layout_toRightOf="#+id/checkBox1"
android:text="Small Text"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:id="#+id/cConNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/cConName"
android:layout_marginLeft="15.0dip"
android:layout_toRightOf="#id/checkBox1"
android:text="Medium Text"
android:textAppearance="?android:textAppearanceMedium" />
</RelativeLayout>
activity_contacts_picker.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected" />
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/btnShow" >
</ListView>
</RelativeLayout>
ContactsPicker.java
public class ContactsPicker extends ListActivity {
protected Object mActionMode;
public int selectedItem = -1;
private Button btnShowContacts;
private ListView myListView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts_picker);
myListView = getListView();
btnShowContacts = (Button) findViewById(R.id.btnShow);
btnShowContacts.setOnClickListener(new View.OnClickListener() {
public void onClick (View v){
Toast.makeText(getApplicationContext(), "Button Clicked", Toast.LENGTH_SHORT).show();
String name = null;
String number = null;
long [] ids = myListView.getCheckedItemIds();
for(long id : ids) {
Cursor contact = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id + "" }, null);
while(contact.moveToNext()){
name = contact.getString(contact.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
number = contact.getString(contact.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
Toast.makeText(getApplicationContext(), "Name: " +name + "\n" + "Number: " + number , Toast.LENGTH_LONG).show();
}
}
});
ArrayList<Map<String, String>> list = buildData();
String[] from = { "name", "purpose" };
int[] to = { R.id.cConName, R.id.cConNum };
SimpleAdapter adapter = new SimpleAdapter(this, list,R.layout.custcontactview, from, to);
setListAdapter(adapter);
}
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.clear();
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null,null);
while (people.moveToNext()) {
String contactName = people.getString(people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if ((Integer.parseInt(hasPhone) > 0)) {
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Map<String, String> NamePhoneType = new HashMap<String, String>();
NamePhoneType.put("Name", contactName);
NamePhoneType.put("Phone", phoneNumber);
list.add(NamePhoneType);
}
phones.close();
}
}
people.close();
startManagingCursor(people);
return list;
}
}

But the problem is the name and number of the contacts are not
appearing as you can see in the image attached
First of all, I guess you checked and see that you have real values in the ArrayList list in the buildData method. Second you use the key names "Name" and "Phone" when you add the values to the HashMap, but in the from String array that you use in the SimpleAdapter you use the values "name" and "purpose". In the from String array you need to have the same keys as you have in the HashMap.
Moreover when i click Show contacts button to show the selected
contacts in Toast that too is not happening.
First, you can't use ListView's default mechanism for checked items when you have a custom row view. If you want to get the checked items you'll need to manage the state of the CheckBox from the row yourself. The getCheckedItemIds() method will not return something valid and the query will fail returning any valid results. Instead you should implement your own custom adapter and return the row's HashMap(which will contain the name and the phone) with SimpleAdapter.getItem method. This way you'll avoid the need to query the contacts again.

call notifyDataSetChanged(); You need to refresh the list..

Related

SQLite get single datum (*single data)(update post)

I'm a beginner in Android. Please help me to solve this simple problem: retrieve a single datum from SQLite.
case 1 :
dbhelper.java
// Getting single part
public lispar Look(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor kr = db.query(TABLE_PART, new String[]{ID,
KODE, NAMA}, ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);
if (kr != null)
kr.moveToFirst();
lispar contact = new lispar(Integer.parseInt(kr.getString(0)),
kr.getString(1), kr.getString(2));
// return contact
kr.close();
db.close();
return contact;
}
main.java
kodcari = (Button) findViewById(R.id.carikod);
kodcari.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
ckodin = kodin.getText().toString(); //wrong string?
parin.getText().toString();
//what should i do?
}
});
partnam = (EditText) findViewById(R.id.namepart);
dbHandle = new DbHandle(this);
}
case 2 :
main.java ()
kodin = (EditText) findViewById(R.id.inkod);
kodcari = (Button) findViewById(R.id.carikod);
kodcari.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SQLiteDatabase db = mDbHelper.getReadableDatabase();
String[] projection = {
FeedEntry._ID,
FeedEntry.KODE,
FeedEntry.NAMPART,
FeedEntry.BELANG
};
// Filter results WHERE "kode" = 'kode part'
String selection = FeedEntry.KODE + " = ?";
String[] selectionArgs = parin.getText().toString(), belangin.getText().toString();//{ "KODE_PART" }; //
// How you want the results sorted in the resulting Cursor
String sortOrder = FeedEntry.KODE + " DESC";
Cursor kr = db.query(
FeedEntry.KODE, // The table to query
projection, // The columns to return
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
if (kr != null)
kr.moveToFirst();
//String parin = kr.getString(
//kr.getColumnIndexOrThrow(FeedEntry._ID)
//);
}
});
main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Looking by Code"
android:textSize="10pt"
android:id="#+id/txkod"
android:layout_marginTop="63dp"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="insert code"
android:textAlignment="center"
android:layout_marginTop="25dp"
android:id="#+id/inkod"
android:layout_below="#+id/txkod"
android:layout_alignLeft="#+id/txkod"
android:layout_alignStart="#+id/txkod"
android:layout_alignRight="#+id/txkod"
android:layout_alignEnd="#+id/txkod" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Look"
android:id="#+id/carikod"
android:layout_below="#+id/inkod"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/codepar"
android:hint="code part"
android:layout_below="#+id/namkod"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/nampar"
android:hint="name part"
android:layout_below="#+id/nampar"/>
</LinearLayout>
Inserting the data is successful, but reading a datum isn't.
(datum means data*)
enter image description here
I'm not at all sure if the following will get you moving. But it appears that you are not getting the ID's of the views kodin and parin. So perhaps try the following:-
kodin = (EditText) findViewById(R.id.inkod);
parin = (EditText) findViewById(R.id.nampar);
More detailed code (untested and written on the fly so may have errors)
If you are using Android Studio or an IDE with debugging, then using that can be really helpful.
kodcari = (Button) findViewById(R.id.carikod);
// Adding the following lines may get the correct string
kodin = (EditText) findViewById(R.id.inkod); //????
parin = (EditText) findViewById(R.id.nampar); //????
kodcari.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
ckodin = kodin.getText().toString(); //wrong string?
parin.getText().toString();
//what should i do? Perhaps the following :-
lipsar myContact = Look(ckodin !!!!CONVERTED TO INT FROM STRING);
// whatever else you need to do with the mycontact .....
}
});
partnam = (EditText) findViewById(R.id.namepart);
dbHandle = new DbHandle(this);
}

how to show list view record from sqlite into second listview on setOnItemClickListener

I have created list view, what I want to do is that when user clicks on first list view the selected record For that Particular Field should show in second list view,
in my code I Just get the item position of the first list view and i pass Selected item of that list view into my second Activity i dont know what i do next
so please give me the code/idea how to do this as I am new in android..
Here is My Code
MainActivity:(First List View)
listView= (ListView) findViewById(R.id.listView);
dbHelper = new SqlLiteDbHelper(this);
try {
dbHelper.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteDatabase=dbHelper.getReadableDatabase();
cursor=dbHelper.gettitles(sqLiteDatabase);
String[] from = new String[] { dbHelper.TITLE };
int[] to = new int[] {R.id.title };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.title_row,cursor,from,to);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor =(Cursor) (listView.getItemAtPosition(position));
String selectedItem = cursor.getString(0);
Intent intent = new Intent(MainActivity.this, SubcategoryActivity.class);
intent.putExtra("selectedItem", selectedItem);
startActivity(intent);
}
});
MainActivity Xmlcode:(Firstlistview)
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Title_row.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/title"
android:layout_gravity="center_horizontal" />
Second Activity:(Second List view)
listView2= (ListView) findViewById(R.id.listView2);
final String selectedData = intent.getStringExtra("selectedItem");
dbHelper = new SqlLiteDbHelper(this);
try {
dbHelper.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteDatabase=dbHelper.getReadableDatabase();
cursor=dbHelper.getsubcategory(sqLiteDatabase,selectedData);
String[] from = new String[] { dbHelper.SUBCATEGORY };
int[] to = new int[] {R.id.subcategory };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.subcategory_row,cursor,from,to);
adapter.notifyDataSetChanged();
listView2.setAdapter(adapter);
Subcategory Xml File:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView2"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
subcategory_row.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/subcategory"
android:layout_gravity="center_horizontal" />
Database CLass:
public Cursor gettitles(SQLiteDatabase db)
{
db = this.getReadableDatabase();
Cursor cursor;
cursor = db.query(true, "record", new String[]{TITLE,ITEMNO + " as _id"}, null, null, TITLE, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
public Cursor getsubcategory(SQLiteDatabase db,String sub)
{
db=this.getReadableDatabase();
Cursor cursor;
cursor = db.query("record",new String[]{SUBCATEGORY},TITLE + "=" +sub,null,null,null,null);
return cursor;
}
Logcat:
Caused by: android.database.sqlite.SQLiteException: near "FOOD": syntax error (code 1): , while compiling: SELECT subcategory FROM record WHERE title=GENERAL FOOD TIPS
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1448)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1295)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1166)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1334)
at com.example.aeiltech.sidd.SqlLiteDbHelper.getsubcategory(SqlLiteDbHelper.java:118)
at com.example.aeiltech.sidd.SubcategoryActivity.onCreate(SubcategoryActivity.java:38)
I am not quite sure what you want to do, however i see two Errors in your code that may help solve the problem. If they don't, please provide a better understandable problem description.
In the onItemClickListener you are trying to cast the item from the List to a String. However the Method getItemAtPosition(position) will pass to the function getItem(position) of the adapter, which in your case will return a Cursor. You cannot cast a Cursor to a String. Therefore your code at this position should look something like this:
Cursor cursor =(Cursor) (listView.getItemAtPosition(position));
String selectedItem = cursor.getString(0);
In your second list view you have the following function call:
cursor=dbHelper.getsubcategory(sqLiteDatabase,sub);
However i don't see where you define sub. My best guess after reading your code is that sub should be the selected title in the first list view. Therefore this call should look like this:
cursor=dbHelper.getsubcategory(sqLiteDatabase,selectedData);

Android ListView and SimpleCursosrAdapter: nothing is showed

A read a lot of docs, but can't figure out what I am doing wrong. I'm just trying to load data with Cursor and show it in a ListView using SimpleCursorAdapter.Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_expense_category);
DBHelper dbHelper = new DBHelper(this);
SQLiteDatabase db = dbHelper.getReadableDatabase();
String q = "SELECT rowid as _id, " + GLO.DBEntry_Categories.COLUMN_CATEGORY +
" FROM " + GLO.DBEntry_Categories.TABLE_NAME;
Cursor cursor = db.rawQuery(q, new String[]{});
cursor.moveToFirst();
Toast toast = Toast.makeText(this, "Read count: " + Integer.toString(cursor.getCount()) + " " + cursor.getString(0), Toast.LENGTH_LONG);
toast.show();
cursor.moveToFirst();
//TODO: use Loader
String[] fromCols = {GLO.DBEntry_Categories.COLUMN_CATEGORY};
int[] toViews = {R.id.MyTextView1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor,
fromCols, toViews, 0);
ListView listView = (ListView) findViewById(R.id.SelectExpenseCategory_list);
listView.setAdapter(adapter);
}
So toast message shows there are 3 items in cursor, and data is peresent (at least in first one, but I'm sure for others too). But nothing is showed in ListView.
Here is a part of my activity layout:
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/SelectExpenseCategory_search"
android:layout_centerHorizontal="true"
android:id="#+id/SelectExpenseCategory_list">
</ListView>
And here is complete file for item layout:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:textColor="#color/cm_dark_green"
android:textSize="24sp">
</TextView>
Any ideas what's wrong?..
You're using the internal layout for the list items: android.R.layout.simple_list_item_1.
The TextView id there is called text1, so instead use this:
int[] toViews = {android.R.id.text1};
If you want to use your own custom layout then change the layout used by your adapter to e.g. R.layout.list_item_layout.

adding values to listView

I am trying to populate a ListView....but I cant add 2 string values from database used in SimpleCursorAdapter....
Any one, help me
Code
ListView.java
public class ListView extends ListActivity {
SQLiteDatabase messagedb;
List<String> senderArray = new ArrayList<String>();
List<String> bodyArray = new ArrayList<String>();
String[] simpleSenderArray = new String[ senderArray.size() ];
String[] simpleBodyArray = new String[ bodyArray.size() ];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_list);
senderArray.toArray( simpleSenderArray );
bodyArray.toArray( simpleBodyArray );
messagedb=ListView.this.openOrCreateDatabase("message",0, null);
//This database created already and add sender and body values...here just open that database
Cursor cur=messagedb.rawQuery("select sender, body from tab2", null);
while(cur.moveToNext())
{
String sender = cur.getString(cur.getColumnIndex("sender"));
String body = cur.getString(cur.getColumnIndex("body"));
senderArray.add(sender);
bodyArray.add(body);
}
cur.close();
messagedb.close();
int[] to = new int[] { R.id.sender_entry, R.id.body_entry };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.my_list_entry, cur,simpleSenderArray, to);
this.setListAdapter(mAdapter);
}
}
my_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
my_list_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/sender_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/body_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
Can somebody help me to populate my ListView?
You have named your Activity ListView which is already a built-in class name, I highly recommend changing it to something unique to prevent any confusion or naming conflicts.
In your SQLite table, you ought to have an _id INTEGER column set as the PRIMARY KEY, Android requires this _id column to bind the data to any ListView, Spinner, etc. (Technically SQLite3 creates a column like this automatically, but I believe it is best to define it yourself.)
messagedb.execSQL(
"CREATE TABLE IF NOT EXISTS tab2(" +
" _id INTEGER PRIMARY KEY," +
" sender INT(13)," +
" body varchar)");
Your code should look more like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_list);
// Using a SQLiteOpenHelper might be best, but I'll assume that this command works
messagedb=ListView.this.openOrCreateDatabase("message",0, null);
Cursor cur = messagedb.rawQuery("select _id, sender, body from tab2", null);
String[] from = new String[] { "_id", "sender", "body" }
int[] to = new int[] { R.id.sender_entry, R.id.body_entry };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.my_list_entry, cur, from, to);
this.setListAdapter(mAdapter);
}
You might want to consider using the SQLiteDatabase.query() methods, I believe it is a touch faster:
Cursor cur = messagedb.query("tab2", new String[] {"_id", "sender", "body"}, null, null, null, null, null);
I also recommend defining static variables for all you column names for future ease-of-coding.
Lastly, this should work for a table without the _id column, but again I don't recommend it:
Cursor cur = messagedb.rawQuery("select rowid as _id, sender, body from tab2", null);

Begginner working with ListAdapters / SQLite Database

My programming knowledge is slim, i discovered Java and the Android SDK some days ago.
I have a SQLiteDatabase, a SQLiteOpenHelper, and a Cursor working properly
( means i think i understood how to create/open a DB using a SQLiteOpenHelper, make queries on my DB and get a cursor )
currently, i'm wrapping i + labName + labCity into a single results String, and display into a single TextView R.id.label
Is it possible to bind labName to R.id.label, and bind labCity to another TextView R.id.label2 ?
Here is the code of my ListActivity i need help with :
public class MainLabList extends ListActivity implements OnItemClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_lab_list);
// DB
GestionDB gdb = new GestionDB(this, GestionDB.DATABASE_NAME, null, GestionDB.DATABASE_VERSION);
SQLiteDatabase theDB = gdb.getWritableDatabase();
// Cursor
String[] columns = {GestionDB.LAB_NAME, GestionDB.LAB_ADDRESS_CITY};
Cursor c =
theDB.query(GestionDB.TABLE_NAME, columns, null, null, null, null, null);
////////
this.setTitle(" " + c.getCount() + " Labs in Local Database");
ArrayList<String> results = new ArrayList<String>();
int i = 0;
c.moveToFirst();
/* Loop through all Results */
do {
i++;
String labName = c.getString(c.getColumnIndex(GestionDB.LAB_NAME));
String labCity = c.getString(c.getColumnIndex(GestionDB.LAB_ADDRESS_CITY));
/* Add current Entry to results. */
results.add("" + i + ": " + labName
+ " (" + labCity + ")");
} while (c.moveToNext());
//need rework
ListView lvLabListing = (ListView) findViewById(android.R.id.list);
ArrayAdapter<String> labListAdapter = new ArrayAdapter<String>(this,
R.layout.listing, R.id.label, results );
lvLabListing.setAdapter(labListAdapter);
lvLabListing.setOnItemClickListener(this);
//
// don't forget to close the database
gdb.close();
And the listing.xml i would like to modify :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:id="#+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#drawable/icon"></ImageView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/label"></TextView>
</LinearLayout>
My GestionDB class is simple, just define some columns if the database doesn't exist, along with some variables.
You should use a CursorAdapter, perhaps a SimpleCursorAdapter, for this. Here is an example.

Categories

Resources