gpt4 book ai didi

java - 如果用户输入某个关键字并显示它,如何使 editText 获取 stringarray 的值?

转载 作者:行者123 更新时间:2023-12-01 16:58:33 25 4
gpt4 key购买 nike

美好的一天,我正在制作一个测验应用程序,需要输入答案,而且我是编程新手。我想知道如果他们没有得到确切的答案,如何或是否可以正确回答问题。

因为给定的问题有句子形式的答案,例如:

问。 “树的 3 个主要部分是什么?”
A.“三个主要部分是枝、叶、根。”

如果他们只回答“分支、叶子、根”,我将使其正确并显示相同 editText 或 Textview 或某些弹出消息的确切答案。我想我只需要另一个 ArrayList 来存储关键字?这种东西的代码是什么?顺便说一句,我有超过 300 个问答。

这是我的编辑文本:

           answer1.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
mp2.start();
switch (category) {
case "Basic":
if (answer1.getText().toString().equalsIgnoreCase(BasicList.get(level).getbasicans1())) {
Toast.makeText(QuestionActivity.this, "Correct!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(QuestionActivity.this, "Wrong!", Toast.LENGTH_SHORT).show();
}
break;

这是我的数组列表。

         final ArrayList<BasicItem> BasicList = new ArrayList<>();
BasicList.add(new BasicItem("What is the Figurative meaning of [1]Water, [2]Field, [3]Fire?", "Word as as ds ds", "Example of example only", "Word that consume"));
BasicList.add(new BasicItem("What is the meaning of [1]B,[2]D,[3]S?", "Betrayal", "Destruction", "Salvation");

感谢您的帮助:)

最佳答案

好的..你可以试试这个

String sentence = "Check this answer and you can find the keyword with this code";

String search = "keyword";

if ( sentence.toLowerCase().indexOf(search.toLowerCase()) != -1 ) {

System.out.println("I found the keyword");

} else {

System.out.println("not found");

}

或者

if ( d.contains("hello")) {
System.out.println("I found the keyword");
}

或者,如果您想使用字符串匹配,

if (d.matches(".*Hey.*")) {
c.setText("OUTPUT: SUCCESS!");
} else {
c.setText("OUTPUT: FAIL!");
}

.* -> 0 个或多个任意字符

嘿 -> 你想要的字符串

关于java - 如果用户输入某个关键字并显示它,如何使 editText 获取 stringarray 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61550253/

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