将输入字符串转换为类别

时间:2019-06-29 17:31:05

标签: java android

我一直在创建新屏幕以从用户输入中添加类别,但是如何将输入字符串转换为类别? 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);
    }

1 个答案:

答案 0 :(得分:0)

QuizDbHelper.getInstance(AddCategory.this).addCategory(new Category(newEntry));