samedi 31 octobre 2015

getting single cell from sqlite into textview

I'm trying to get single data cell from my DB into text view

this is the function i wrote it in my sqliteopenhelper class

public Cursor getMainData(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor result = db.rawQuery("select NAMEPPL from "+Table_name2,null);
return result;}

and this what i did it in the main activity class ,

its crashing once i lunch the app and giving me something related to buffer while I'm not using any buffers

is this the write way?

Thank you in advance.

public class MainActivity extends AppCompatActivity {

DB db;
Button addmed,addpl;
TextView PPLNAMERES;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    PPLNAMERES = (TextView)findViewById(R.id.PPLAGETXTVIEW);

    db = new DB(this);
    listView();
}

public void addmedView(View view){
    Intent ADDMEDVIEW = new Intent(this,ADDMEDCINEVIEW.class);
    startActivity(ADDMEDVIEW);

}
public void addpplview(View view){
    Intent ADDPPLVIEWS = new Intent(this,ADDPPLVIEW.class);
    startActivity(ADDPPLVIEWS);
}
 public void listView(){
Cursor res= db.getMainData();
if(res.getCount()==0){
    Toast.makeText(MainActivity.this,"No Data",Toast.LENGTH_LONG).show();
    return;
}
else{
    PPLNAMERES.setText(res.getString(0));

}}

Aucun commentaire:

Enregistrer un commentaire