ฉันเขียนแอปพลิเคชัน Android ตัวแรกของฉัน CRUD แบบง่าย แต่หลังจากที่ฉันเปลี่ยน GridView เป็น TableLayout ฉันได้รับข้อผิดพลาดดังต่อไปนี้:
android.widget.TableRow cannot be cast to android.widget.TableLayout
นี่คือกิจกรรมของฉัน:
public class AllActivity extends Activity {
private SQLiteDatabase sampleDB;
private TableLayout tableList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all);
sampleDB = this.openOrCreateDatabase("my_app",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
String query = "SELECT * FROM BOOKS;";
Cursor cursor = sampleDB.rawQuery(query, null);
tableList = (TableLayout)findViewById(R.id.tableList);
if(cursor.moveToFirst())
{
do
{
TableRow row = new TableRow(this);
TextView id = new TextView(this);
id.setText(""+cursor.getLong(0));
TextView title = new TextView(this);
title.setText(cursor.getString(1));
TextView author = new TextView(this);
author.setText(cursor.getString(2));
row.addView(id);
row.addView(title);
row.addView(author);
tableList.addView(row);
}while(cursor.moveToNext());
}
}
}
มุมมองของฉัน:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TableRow>
</LinearLayout>
มีเคล็ดลับอะไรบ้างที่ฉันทำผิด
ฉันทำทุกอย่างเหมือนใน พิมพ์ออกมา เนื้อหา ArrayList ใน Android TableLayout แต่ไม่สามารถทำงานได้