我是 Android 初学者,我在 string.xml 文件上有 stringArray 资源..我需要检查项目名称是否正确,然后我必须做一些事情..我输入了正确的项目名称,但它转到其他部分..可能问题出在 if(itemname=stringArray).. 请给我解决方案..
String[] drugs = getResources().getStringArray(R.array.Drugsinfo);
if(editext1.getText().equals(drugs))
{
Toast.makeText(getApplicationContext(), "some usefull info for you buddy ...", Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(MainActivity.this, Descriptionjava.class);
startActivity(myIntent);
}
else
{
Toast.makeText(getApplicationContext(), "Wrong pill name !! check out the list",Toast.LENGTH_LONG).show();
bt1.setEnabled(true);
}
}
最佳答案
试试这个:
String[] bob = { "this", "is", "a", "really", "silly", "list" };
if (Arrays.asList(bob).contains("silly")) {
// true
}
“silly”是您的 EditText 的文本。
要从编辑文本中获取文本并根据您的评论进行比较,请使用以下内容:
if(yourEditText.getText().toString().trim().equalsIgnoreCase("silly"))
{
//do your work here
}
谢谢。
关于java - 在if语句中调用StringArray来检查项目名称是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33236139/