Saya menulis aplikasi Android pertama saya, CRUD sederhana. Tapi setelah saya mengubah GridView ke TableLayout saya mendapatkan kesalahan berikut:
android.widget.TableRow cannot be cast to android.widget.TableLayout
Inilah aktivitas saya:
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());
}
}
}
Pandangan ku:
<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>
Ada tips apa yang saya lakukan salah?
Saya melakukan semuanya seperti di Print out Konten ArrayList di Android TableLayout tetapi tidak dapat berfungsi.