我目前正在創建一個應用程序,該應用程序將讀取NFC標籤,並根據字符串數組查看標籤的文本以查看它是否存在。如果標籤區分大小寫正確無誤'測試',而不是'測試'。我嘗試了各種方法,沒有奏效。請有人看看我的代碼,看看哪個是最適合我的解決方案。如何在Android中使字符串數組不區分大小寫
下面是相關的代碼:如果你不這樣做的東西不區分大小寫,嘗試上的任何單詞的第一個字母數組中尋找它之前
String[] dd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dd = getResources().getStringArray(R.array.device_description);
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
if(Arrays.asList(dd).contains(result)) {
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(800);
//mText.setText("Read content: " + result);
Intent newIntent = new Intent(getApplicationContext(), TabsTest.class);
Bundle bundle1 = new Bundle();
bundle1.putString("key", result);
newIntent.putExtras(bundle1);
startActivity(newIntent);
Toast.makeText(getApplicationContext(), "NFC tag written successfully!", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), result + " is not in the device description!", Toast.LENGTH_SHORT).show();
}
}
}
您可以編寫一個自定義方法來檢查該方法,而不是依賴於API方法。 – NINCOMPOOP