gpt4 book ai didi

java - isSelected 方法总是返回 false

转载 作者:行者123 更新时间:2023-12-01 17:18:37 26 4
gpt4 key购买 nike

我使用 isSelected 作为复选框。调试显示该方法无论是否选中都返回false,没关系。

来自 xml 的部分:

 <CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Watched"
android:layout_margin="10sp" />

和代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editmovie);

final DBHandler myMovies = new DBHandler(this);
final EditText edname = (EditText)findViewById(R.id.editText1);
final EditText eddetails = (EditText)findViewById(R.id.editText2);
final EditText edurl = (EditText)findViewById(R.id.editText3);
final CheckBox chwatched = (CheckBox)findViewById(R.id.checkBox1);
Button btn = (Button)findViewById(R.id.button1);
Intent intent = getIntent();
getId = intent.getStringExtra("id");
if (getId != null)
{
Cursor cursor = myMovies.getMovie(getId);
cursor.moveToFirst();
edname.setText(cursor.getString(1));
eddetails.setText(cursor.getString(2));
edurl.setText(cursor.getString(3));
String iswatched = cursor.getString(4);
if ((iswatched.equals("true")
chwatched.setSelected(true);
else
chwatched.setSelected(false);
flag=true;
}

btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(EditMovie.this , MainActivity.class);
String name = edname.getText().toString();
String details = eddetails.getText().toString();
String url = edurl.getText().toString();
boolean wt = chwatched.isSelected();
String watched = String.valueOf(wt);
if (flag)
myMovies.updateMovie(new Movie(name, details, url, watched));
else
myMovies.addMovie(new Movie(name, details, url, watched));

startActivity(intent);

}
});
}

}

由于某种原因,wt 总是收到错误信息...

最佳答案

尝试使用checkBox.isChecked()checkBox.setChecked(true/false)

关于java - isSelected 方法总是返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20356505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com