开发者

How to add in TextView new data(1 textView = 1 name), from Data Base? in a cycle

I have tableLayout with 3 textView in a TableRow. How to add in TextView new data(1 textView = 1 name), from Data Base? thats doesnt work:

my cursor say: select * from TABLE_NAME

  Cursor cursor = database.query(TABLE_NAME,
    new String[] {"*"},
 null, null,null,null,"_id");  



    cursor.moveToFirst();
        try {
      if (!cursor.moveToFirst()) {
          return;
      }

      do {
          TextView textView = (TextView)findViewById(R.id.edit);
          textView.setText(cursor.getString(0));
            } while (cursor.moveToNext());
  } finally {
     cursor.close();
  }

My table:

        _id student
         1   Said
         2   Bill
    开发者_运维知识库     3   John

etc


You are overwriting your TextView identified by edit each time you call setText(String). You may need to create new instances of TextView programatically.

TableRow row = new TableRow(context);
do {
    TextView textView = new TextView(context);
    textView.setText(cursor.getString(0));
    row.addView(textView); //add each textview to your row
} while (cursor.moveToNext());

myTableLayout.addView(row); //add your row to your table

If you already have a TableLayout, you can add a TableRow to it using addView(View v). Add new instances of TextView to your TableRow and you should get what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜