java - Display multiple result array -


so far, got app working already, i'm faced issue. fyi, app getting user input (the user types in sentence , app ambiguous word/s , display meanings).

this code have:

final string[] words = {"cowboy", "animal" , "monster", "duck"}; final string[] meanings = { "meaning1", "meaning2", "meaning3", "meaning4" };  private void initcontrols() { // todo auto-generated method stub text = (edittext) findviewbyid (r.id.edittext1);  view = (textview) findviewbyid (r.id.textview1);  clear = (button) findviewbyid (r.id.button2);  clear.setonclicklistener(new view.onclicklistener() {      @override     public void onclick(view v) {         // todo auto-generated method stub         text.settext("");         view.settext("");     } });  ok = (button) findviewbyid (r.id.button1); ok.setonclicklistener(new view.onclicklistener() {      @override     public void onclick(view v) {         // todo auto-generated method stub         findambiguousword();     }    }); }  private void findambiguousword(){ string string = text.gettext().tostring();  int index = 0;  (int = 0; < words.length; i++) {     if (string.tolowercase().contains(words[i].tolowercase())) {         check = true;         index = i;     }  }  view.settext(check ? meanings[index] : "no ambiguous word/s found."); } 

but whenever type sentence like:

 friend cowboy. fond of duck. 

it displays first word i.e. cowboy. how display other words? needed , appreciated. in advance!

you add results in collection, instance set or list:

private void findambiguousword(){ string string = text.gettext().tostring(); // create set store results set<string> result = new hashset<string>(); (int = 0; < words.length; i++) {     if (string.tolowercase().contains(words[i].tolowercase())) {         // ambiguous word, need meaning!         result.add(meanings[i]);     }  }  // display results if there view.settext(result.isempty() ? "no ambiguous word/s found." : result.tostring()); } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -