Android 如何将用户在editText中键入的内容与我';我在我的项目中创建了内置

Android 如何将用户在editText中键入的内容与我';我在我的项目中创建了内置,android,arrays,Android,Arrays,我有一个字符串数组,在数组下面有一个toast,它从数组中随机选择元素并显示在屏幕上 在显示toast的屏幕中,用户在编辑文本中键入他所看到的toast 我的问题是:如何将editText中的字符串与从字符串数组中选择的随机元素进行比较?您将在显示之前存储数组中显示的toast字符串,然后使用if语句比较这两个字符串: //Where you declare your variables and objects @ the top of your class String toastString

我有一个字符串数组,在数组下面有一个toast,它从数组中随机选择元素并显示在屏幕上

在显示toast的屏幕中,用户在
编辑文本中键入他所看到的toast


我的问题是:如何将
editText
中的字符串与从字符串数组中选择的随机元素进行比较?

您将在显示之前存储数组中显示的toast字符串,然后使用if语句比较这两个字符串:

//Where you declare your variables and objects @ the top of your class
String toastString = null;
在显示toast的方法中

toastString =  your randomly selected string;
Toast.makeText(getApplicationContext(), toastString, Toast.LENGTH_LONG).show();
用你的比较法

String editTextEntry = editText.getText().toString();
if(editTextEntry.equals(toastString)){
    //do something, display something, whatever you need to do
}
else{
    //Strings didn't match
}

我的答案对你有用吗?组件格式化,拼写错误修复