listview - How to receive result from implicit intent from adapter in fragment? -




i working on pronunciation application have recognizer intent on every list item adapter user record pronunciation , gets percentage of accuracy.

thus, need invoke implicit intent adapter. challenge is: have activity (numbersactivity) hosts fragment (numbersfragment) contains adapter. thus, receive result of intent on numbersactivity.

1) know how getback result activity list_item invoked intent.(you can see want inside code)

code

wordadapter

public class wordadapter extends arrayadapter<word> { activity mactivity; context mcontext; boolean isenable = false; private static final int req_code_speech_input = 100; private button mspeakbtn; private boolean isconnected = true; connectiondetector connectiondetect;  public wordadapter(context context, activity activity, arraylist<word> pwords, int colorid) {     super(context, 0, pwords);     mactivity = activity;     mcontext = context; }  @override public view getview(int position, view convertview, viewgroup parent) {     view listitemview = convertview;     if (listitemview == null) {         listitemview = layoutinflater.from(mcontext).inflate(                 r.layout.list_item, parent, false);     }     final word local_word = getitem(position);     final imagebutton playbutton = (imagebutton) listitemview.findviewbyid(r.id.playbutton)      connectiondetect = new connectiondetector(mcontext);      mspeakbtn.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             isconnected = connectiondetect.isconnected();              if(isconnected){                 startvoiceinput();                //i want data here, display user             }             else{                 toast.maketext(mactivity, "unavailable offline, check faq enable offline", toast.length_short).show();             }         }      });       return listitemview; }  private void startvoiceinput() {     intent intent = new intent(recognizerintent.action_recognize_speech);             intent.putextra(recognizerintent.extra_language_model, recognizerintent.language_model_free_form);            intent.putextra(recognizerintent.extra_language, "id");             intent.putextra(recognizerintent.extra_prompt, "hello, how can you?");           try {         mactivity.startactivityforresult(intent, req_code_speech_input);                } catch (activitynotfoundexception a) {         log.v(log_tag, "problem in getting recognitionintent response");     } }    

}

numbersactivity

public class numbersactivity extends appcompatactivity { private static final int req_code_speech_input = 100; @override protected void oncreate(@nullable bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.category_layout);    getsupportfragmentmanager().begintransaction()             .replace(r.id.categorycontainer, new numbersfragment())             .commit(); }  @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     switch (requestcode) {         case req_code_speech_input: {             if (resultcode == result_ok && null != data) {                                    arraylist<string> result = data.getstringarraylistextra(recognizerintent.extra_results);                                 //i want send data here adapter             }             break;         }     } } 

}

thank in advance.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -