我正在尝试学习如何开发Android应用。我正在进行标准练习' Notepadv3' LINK并根据我的目的进行调整。
这是一个面向数据库的类,以前(在练习中)有两个字符串字段。我想添加一个布尔字段,以允许一个值表明记录是否已完成。
首先,我添加了一个' CheckBox'变量,这是对的吗?:
public class TaskEdit extends Activity {
private EditText mTitleText;
private EditText mBodyText;
private CheckBox mCompleteBoolean; /* <<< - I added this, is this right */
private Long mRowId;
private TasksDbAdapter mDbHelper;
然后我遇到以下方法的问题:
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString(); /* Copied this line to the one below, but need a boolean field */
Boolean complete = mCompleteBoolean.getText().toString(); /* << Not working as Boolean - getting 'Type mismatch: cannot convert from String to Boolean' << */
if (mRowId == null) {
long id = mDbHelper.createTask(title, body, complete);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateTask(mRowId, title, body, complete);
}
}
答案 0 :(得分:1)