简体   繁体   中英

How to SQLite database to Custom ListView?

I have been working on a android app which implements a Custom Listview via String arrays in the strings.xml folder. But now i want to incorporate a Sq-lite database to get the data for the Listviews it looks like this but i want the data from a sq-lite database : 在此处输入图片说明

How would i go about switching from String arrays and or getting the data from the database first

Edit: Ive looked into implementing sqlite already Want i want to know is how do i get the data from the database to the listview?

Tutorial to Implement SQLite in Android.

Firstly you need to implement the SQLite database and then make a query in the database to get all the data into a string array and then like before use that string array to fill up the ListView. You can do something like this:

List<String> nameArray = new ArrayList<String>();
List<String> chargeArray = new ArrayList<String>();
String data="";
while(crs.moveToNext()){
    data = crs.getString(crs.getColumnIndex("NAME"));
    nameArray.add(data);
    data = crs.getString(crs.getColumnIndex("CHARGE"));
    chargeArray.add(data);
}

You can check this link for the reference.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM