我創建了一個表佈局命名錶,我想用下面的表格與文本視圖添加表參考ID(R.id.table)我想動態創建表格佈局!幫我在這
TableLayout table = (TableLayout) findViewById(R.id.table);
和填充
將應用程序,當我執行這墜毀..我調試,並仔細檢查代碼 只見R.id.table值返回空但沒有編譯器錯誤
這是我table.xml,其佈局文件
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrol"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/dummy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TableLayout
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="@+id/tablerow"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
</LinearLayout>
是我的做法是對還是錯..我是否要參考表表的行ID ??有沒有什麼辦法可以創建動態表格佈局?
我googling所有這一切,但我沒有罰款任何合適的例子爲此..任何人都可以幫助我在這?
在此先感謝
您可以發佈,這可能是有用的你的XML和代碼?基本上,如果findViewById返回null,這意味着在XML文件中沒有這樣的id的視圖。編譯器不會抱怨,因爲它在語法上都是正確的。 –