我想在運行期間在我的android應用程序中動態創建一組複選框。除了按鈕,應用程序什麼都不顯示。我忘了什麼?提前致謝!動態複選框創建
public class DataNotificationSurvey extends Activity {
private Date timeStamp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.datanotifylayout);
final Button notifySubmitButton = (Button) findViewById(R.id.notifySubmitButton);
TableLayout t1 = (TableLayout)findViewById(R.id.notificationTableLayout);
for(int i = 0; i < 5; i++) {
TableRow tr = new TableRow(this);
CheckBox chk = new CheckBox(this);
chk.setText(Integer.toString(i));
tr.addView(chk);
t1.addView(tr);
}
notifySubmitButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
//My xml layout, will be changing this later to the one posted below to see if it works.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/notificationLinearLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/notificationTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Static Button"/>
</TableRow>
</TableLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/notifySubmitButton"
android:text="Submit"></Button>
</LinearLayout>
請發佈您的layout.xml以及代碼看起來沒問題,所以問題可能在那裏。 – harpo 2011-04-04 03:53:29
@harpo:添加了xml,稍後我會更改以反映發佈爲答案的xml。如果它有效,我會讓你知道。但是,如果您在xml或其他任何地方發現問題,請通知我。謝謝 – prolink007 2011-04-04 15:54:44