-1

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 :enter image description here

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?

JavaScrub
  • 133
  • 9
  • How about to google something about how to implement SQLite database into android app? – nyarian Mar 05 '18 at 15:27
  • You need an `Adapter`, you can follow [this answer](https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) for a working example. For the Database part, you'll need first to retrieve all of your records in a `List` and then, following the example, just pass it to the `Adapter`. – LS_ Mar 05 '18 at 15:36

1 Answers1

1

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.

Pronoy999
  • 645
  • 6
  • 25