Hi I had asked before how do I update listview and got suggestion to make use of ArrayAdapter.I follow the thing now the issue is about it's updating listviews but not with expected values some object .
My code is like this:
Cursor cursor = db.rawQuery("SELECT count(*) FROM BOOKMARKS ", null);
//if any contact found moveToFirst of that contacts or points to 1st email
cursor.moveToFirst();
//checking columns exhist or not
if (cursor.getInt(0) > 0)
{
//get all the contacts from table 'BOOKMARKS'
c = db.rawQuery("SELECT * FROM BOOKMARKS", null);
//get the index of mentiond and required columns
ID = c.getColumnIndex("ID");
booktitl = c.getColumnIndex("Booktiltle");
audiotime=c.getColumnIndex("BookmarkTime");
// Check result.
c.moveToFirst();
if (c != null)
{
// Loop through all Results
do
{
cont = new String[3];
cont[0] = Integer.toString(c.getInt(ID));
cont[1] = c.getString(booktitl);
cont[2] = c.getString(audiotime);
audiobooks.add(cont);
}
while(c.moveToNext());
c.close();
db.close();//close db resources
ArrayAdapter<String[]> arrayAdapter1=new ArrayAdapter<String[]>(this, R.layout.row3, R.id.itemr1,audiobooks);
lv.setAdapter(arrayAdapter1);
How do i get the string value on listview?Actually the values fetching from database and storing into Arraylist.At present I am displaying some object value on listview but I want to display content that "audiobooks" holds. Please help me to solve it.
You can't give the ArrayAdapter
the type String[]
, because you're giving it a List
called audiobooks.
Also, I'm not sure if the standard ArrayAdapter
can handle a datatype List<String[]>
. It might not work. You would have to make your own implementation of the ArrayAdapter
by extending it, if it shouldn't work.
If I understand correctly, you want to populate a ListView with data from each row from your database. You must create a new class of type Audiobook with the member variables corresponding with database row. Then create a layout in your res/layouts folder that must show your object's data. Create a new class extending ArrayAdapter class, in which you inflate views with created layout and populate listview with childs. Then in your main you set the new adapter to the list.
The ArrayAdapter should look like this:
public class AudiobookAdapter extends ArrayAdapter<Audiobook> {
// constructor
// here you populate each view and put it in listview
public View getView (int position, View convertView, ViewGroup parent)
{
}
}
This is a start line, you should read more about extending arrayadapters and custom ListViews.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.