Android Studio how to retrieve data from Sqlite database and display it into textview

0 votes

I built a SQLite Database and added the data to it in my app. And right now I want to get data out of it, but I only want to insert one data, get it, get it back, and then display it in a TextView.

public class Db_sqlit extends SQLiteOpenHelper{

    String TABLE_NAME = "BallsTable";

    public final static String name = "db_data";

    public Db_sqlit(Context context) {
        super(context, name, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table "+TABLE_NAME+" (id INTEGER PRIMARY KEY AUTOINCREMENT, ball TEXT)");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
        onCreate(db);
    }

    public boolean insertData(String balls){
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues contentValues = new ContentValues();

      contentValues.put("ball",balls);

      long result = db.insert(TABLE_NAME,null,contentValues);
      if(result == -1){
          return false;
      }
      else
          return true;
    }

    public void list_balls(TextView textView) {

        Cursor res = this.getReadableDatabase().rawQuery("select ball from "+TABLE_NAME+"",null);
        textView.setText("");
        while (res.moveToNext()){
            textView.append(res.getString(1));
        }  
    }
}

Can someone please help me with this?

Sep 2, 2022 in Database by Kithuzzz
• 38,000 points
1,534 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
2 answers

How to send data to my database from html and css Contact Us Form?

Hello @Sign, It is simple to create contact ...READ MORE

answered Aug 4, 2020 in Database by Niroj
• 82,840 points
36,038 views
0 votes
0 answers

Displaying ALL data from sqlite database into listview in tabbed activity

I've been struggling with this problem for ...READ MORE

Aug 20, 2022 in Database by Kithuzzz
• 38,000 points
3,180 views
0 votes
0 answers

Display data from SQL database into php/ html table.

I want to display one of my ...READ MORE

Aug 27, 2022 in Database by Kithuzzz
• 38,000 points
872 views
+2 votes
1 answer

How to export data from MySql to a CSV file?

If you are using MySql workbench then ...READ MORE

answered Jan 4, 2019 in Database by Priyaj
• 58,020 points
1,584 views
0 votes
1 answer

How to load data of .csv file in MySQL Database Table?

At first, put the dataset in the ...READ MORE

answered Jul 5, 2019 in Database by Reshma
1,462 views
+1 vote
1 answer

How to migrate a PostgreSQL database into a SQLServer one?

Hello @kartik, The easier way to accomplish this. First ...READ MORE

answered May 13, 2020 in Database by Niroj
• 82,840 points
1,041 views
0 votes
0 answers

How to retrieve data from sqlite database in android and display it in TextView

I'm studying Android. I'm having trouble solving ...READ MORE

Aug 11, 2022 in Database by Kithuzzz
• 38,000 points
4,837 views
0 votes
0 answers

SQLite in Android How to update a specific row

For a time now, I've been attempting ...READ MORE

Aug 11, 2022 in Database by Kithuzzz
• 38,000 points
1,734 views
0 votes
0 answers

Create SQLite database in android

In my project, I want to construct ...READ MORE

Sep 4, 2022 in Database by Kithuzzz
• 38,000 points
512 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP