我一直在创建新屏幕以从用户输入中添加类别,但是如何将输入字符串转换为类别? newEntry
需要进行转换。
//Code for button:
button_insert_cat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
String newEntry = textBoxInsert.getText().toString();
if (textBoxInsert.length() != 0) {
QuizDbHelper.getInstance(AddCategory.this).addCategory(newEntry);
toastMessage("Added successfully!");
textBoxInsert.setText("");
} else {
toastMessage("You must put something in the text field!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
});
我正在尝试调用的方法:
public void addCategory(Category category) {
db = getWritableDatabase();
insertCategory(category);
}
答案 0 :(得分:0)
QuizDbHelper.getInstance(AddCategory.this).addCategory(new Category(newEntry));