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

最佳答案

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

关于java - 将输入字符串转换为类别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56819510/

10-10 07:53