How to get string value from string array in Android -


i trying create application reads nfc tag , checks tag against strings in string array , sets text on activity. have got working checks if string exists , sets text in new activity, want able specify string want check against within array, because there multiple strings in nfc tag want display in new activity. have tried it:

result == getresources().getstring(r.string.test_dd) 

here relevant code:

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(doesarraycontain(dd, result)) {             vibrator v = (vibrator)getsystemservice(context.vibrator_service);             v.vibrate(800);                     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 + " not in device description!", toast.length_short).show();             }     } } 

edit:

here method used , please can me problem:

public static boolean doesarraycontain(string[] array, string text) {     (string element : array) {         if(element != null && element.equalsignorecase(text)) {              return true;         }     }     return false; } 

for comparing equality of strings (and other objects) use equals() method. == compares identity of objects (same string object).


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -