i want to display data from SQLite database to my custom listview
this my activity:
public class Main_activity extends Activity implements OnItemClickListener{
public static final String[] titles = new String[] { "Strawberry",
"Banana", "Orange" };
public static final String[] descriptions = new String[] {
"It is an aggregate accessory fruit",
"It is the largest herbaceous flowering plant", "Citrus Fruit"
};
ListView listView;
List<RowItem> rowItems;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(titles[i], descriptions[i]);
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.list);
CustomBaseAdapter adapter = new CustomBaseAdapter(this, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Toast toast = Toast.makeText(getApplicationContext(),
"Item " + (position + 1) + ": " + rowItems.get(position),
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
in this activity, listview will showing data from string titles and description, now i want replace those string, with my data from sqlite database. can anyone tell me how can to do that ?
provide tutorial links that lead to the problem is also very helpful
Create database
and create custom listview using base adapter like below
Get data from database:
finally add adapter
If you need more help please see the below Url
http://mylearnandroid.blogspot.in/2014/04/android-sqlite-with-custom-listview.html