简体   繁体   中英

How to fetch data into a textview?

This is my code to fetch database values into the listview .

private void fetchData2() {
    db = helper.getReadableDatabase();
    Cursor c = db.query(DBhelper.TABLE2, null, null, null, null, null, null);
    adapter = new SimpleCursorAdapter(
                this,
                R.layout.row2,
                c,
                new String[]{DBhelper.Amount},
                new int[]{R.id.lbl});
    list.setAdapter(adapter);
}

I just want to change this code to get the values into a textview ,

You can do like this...

if(c.moveToFirst()){

String data = c.getString(c.getColumnIndex("Column's Index"));

yourTextView.setText(data);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM