0
我寫了我的第一個android應用程序,簡單的CRUD。但我改變了GridView控件之後TableLayout我獲得以下錯誤:android.widget.TableRow不能轉換爲android.widget.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>
任何提示,我究竟做錯了什麼?
我做了像Print out ArrayList content in Android TableLayout一樣的一切,但不能得到它的工作。
當然!該死......愚蠢的錯誤。我確定我從可視化編輯器拖動了TableLayout。感謝幫助。我會在8分鐘內接受答案 – user1409508