在android上预选复选框和微调器
我试图让xml显示预选的复选框和微调器,或者基于我从数据库中获得的变量(即,用户是否已经为复选框选择了选项,或者用户已经选择了微调器上的选项) 复选框和微调器的xml代码如下在android上预选复选框和微调器,android,android-spinner,android-checkbox,Android,Android Spinner,Android Checkbox,我试图让xml显示预选的复选框和微调器,或者基于我从数据库中获得的变量(即,用户是否已经为复选框选择了选项,或者用户已经选择了微调器上的选项) 复选框和微调器的xml代码如下 <CheckBox android:id="@+id/che" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="itemClicked" /
<CheckBox
android:id="@+id/che"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="itemClicked" />
<Spinner
android:id="@+id/tmrs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
正如你所看到的,我是一个android新手,所以你可能需要为我解释清楚。。我很感激能得到的任何帮助
提前感谢。如果您的意思是它不在onCreate{}中?我以后再试试。提前谢谢你的提示。你说得对,它很有效!我觉得自己有点像个白痴。谢谢,你知道微调器是如何工作的吗?我犯了比这更大的错误,所以不用担心:)你可以使用
spinner微调器=(微调器)findViewById(R.id.spinner\u id)设置微调器项;微调器设置选择(int selectionPosition)代码>非常感谢。你的两条简单评论使我免于数小时毫无意义的挠头
public class Optio extends Activity implements AdapterView.OnItemSelectedListener{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.optio);
tqo = (Spinner) findViewById(R.id.toq);
ArrayAdapter adapter=ArrayAdapter.createFromResource
(this, R.array.mpm, android.R.layout.simple_spinner_item);
tqo.setAdapter(adapter);
tqo.setOnItemSelectedListener(this);
}
///my own code below, no errors but doesn't work
public void tree(View v) {
boolean isChecked = true;
CheckBox cb = (CheckBox)findViewById(R.id.unrt);
cb.setChecked(isChecked);
}
}