-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?

2
  • How about to google something about how to implement SQLite database into android app? Commented Mar 5, 2018 at 15:27
  • You need an Adapter, you can follow this answer 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. Commented Mar 5, 2018 at 15:36

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks @Pronoy sorry seems simply but i was overthinking it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.