0
嗨全部 我试图动态更改我的复选框。由于某种原因,该应用程序抛出我的例外。 我做错了什么? 这是我的Java代码:android动态更改复选框问题
package com.school.commtest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.TableLayout;
import android.widget.TableRow;
public class OtherPlacesMenu extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CheckBox c1 = (CheckBox)this.findViewById(R.id.schools);
c1.setChecked(true);
setContentView(R.layout.otherplacesmenu);
}
}
,这是XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/table">
<TableRow android:layout_height="fill_parent" android:layout_width="wrap_content" android:id="@+id/tableRow1">
<CheckBox android:text="School" android:id="@+id/schools" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</TableRow>
<TableRow android:layout_height="fill_parent" android:layout_width="wrap_content" android:id="@+id/tableRow2">
<CheckBox android:text="Supermaker" android:layout_height="wrap_content" android:id="@+id/supermarkets" android:layout_width="wrap_content"></CheckBox>
</TableRow>
<TableRow android:layout_height="fill_parent" android:layout_width="wrap_content" android:id="@+id/tableRow3">
<CheckBox android:text="Gardens" android:layout_height="wrap_content" android:id="@+id/gardens" android:layout_width="wrap_content"></CheckBox>
</TableRow>
</TableLayout>
我敢肯定它的一个简单的问题,但我不能在任何地方找到答案。 p.s. 我不能在xml中将复选框的值设置为true,因为我稍后想要从用户设置中更改复选框。 10x!
我知道这是一个简单的问题:) – doron 2011-05-07 15:52:53