These are chat archives for Trinea/android-open-project

6th
Feb 2017
Abdelaziz
@bardich
Feb 06 2017 13:00
Hi guys
please i have a probelm, how can i get data from my database sqlite to display it into textview in activity
Hi i need help.....
Abdelaziz
@bardich
Feb 06 2017 13:48
@soumyaRauth Please can you tell me how can i fix this problem to get data from my sqlite database

public class MainActivity extends AppCompatActivity {

private SQLiteDatabase db;
public Cursor cursor;
TextView myText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {

        SQLiteOpenHelper myDatabase = new myDatabase(this);
        db  = myDatabase.getWritableDatabase();


        //Get Data From the table using a cursor

        String[] columns  = {"FieldIt"};
        cursor = db.query("FIELDS", columns,null, null, null, null, null);

        while ( cursor.moveToNext()) {
                String name = cursor.getString(0);
                String name1 = cursor.getString(1);
                String name2 = cursor.getString(2);
                String name3 = cursor.getString(3);

                myText.setText(name);

            }


    } catch ( SQLiteException e ) {
        Toast toast = Toast.makeText(this, "Error Database",  Toast.LENGTH_SHORT);
        toast.show();
    }


}

@Override
protected void onDestroy() {
    super.onDestroy();
    cursor.close();
    db.close();

}

}