How To Add Custom Adapter To The Activity To Make The List Appear In The Activity?
i have an android activity that use sqlite database and listview that extend baseAdapter. what i need is to display the data included in the sqlite to be displayed in the list vie
Solution 1:
Way to fetch data from cursor and then passing that arraylist to your custom adapter. then finally bind adapter to listview.
startManagingCursor(cursor);
ArrayList<ItemDetails> itemdetailsList = new ArrayList<ItemDetails>();
ItemDetails objItem;
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
objItem = new ItemDetails();
stad_name = cursor.getString(cursor.getColumnIndex("stad_name_FIELDNAME"));
team1 = cursor.getString(cursor.getColumnIndex("team1_FIELDNAME"));
. . .
itemdetailsList.add(objItem);
cursor.moveToNext();
}
MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(YourActvity.this,
itemdetailsList);
listview.setAdapter(adapter);
Solution 2:
Simpley create an instance of your adapter in your activity or your fragment and call to:
YourAdapteradapter=newYourAdapter(getActivity(), yourItems);
listView.setAdapter(yourAdapter)
for examples please refer to:
Solution 3:
Simpley create an instance of your adapter in your activity
MySimpleArrayAdapteradapter=newMySimpleArrayAdapter(YourActvity.this,
items);
listview.setAdapter(adapter);
Solution 4:
You need to make one global ArrayList
for ItemDetails
class. Like,
ArrayList<ItemDetails> itemdetailsList = new ArrayList<ItemDetails>();
after that pass this arraylist to your custom adapter. Like,
CustomAdapterMatchScheduleadapter=newCustomAdapterMatchSchedule(getActivity(), itemdetailsList);
and after that set that adapter to ListView
.
listview.setAdapter(adapter);
Post a Comment for "How To Add Custom Adapter To The Activity To Make The List Appear In The Activity?"