java - Text to speech not working while using that one in listitem click and myactivity is in Tabactivity -
i have dynamic listview ,while clicking list item,that string array has been converted text speech function,i store string array in string , convert text speech.
here included code..
public class ttslist extends listactivity implements texttospeech.oninitlistener { private static final int activity_create=0; private static final int activity_edit=1; private ginfydbadapter mdbhelper; private simplecursoradapter dataadapter; listview lv; public button btnadd1; private texttospeech tts; string typed1; public string praystring; public textview txttext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tts_list); lv =(listview)findviewbyid(r.id.list); mdbhelper = new ginfydbadapter(this); btnadd1 = (button)findviewbyid(r.id.btnadd); btnadd1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { createproject(); } }); mdbhelper.open(); filldata(); registerforcontextmenu(getlistview()); } @suppresslint("newapi") @suppresswarnings("deprecation") private void filldata() { mdbhelper.open(); cursor projectscursor = mdbhelper.fetchallprojects1(); //startmanagingcursor(projectscursor); // create array specify fields want display in list (only title) string[] = new string[]{ginfydbadapter.category_column_prayername,ginfydbadapter.category_column_wdate}; // , array of fields want bind fields (in case text1) int[] = new int[]{r.id.text1,r.id.date}; dataadapter = new simplecursoradapter( this, r.layout.activity_row2, projectscursor, from, to, 0); setlistadapter(dataadapter); edittext myfilter = (edittext) findviewbyid(r.id.myfilter); myfilter.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { dataadapter.getfilter().filter(s.tostring()); } }); dataadapter.setfilterqueryprovider(new filterqueryprovider() { public cursor runquery(charsequence constraint) { return mdbhelper.fetchprojectbyname(constraint.tostring()); } }); tts = new texttospeech(this, this); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. super.oncreateoptionsmenu(menu); menuinflater mi = getmenuinflater(); mi.inflate(r.menu.activity_main, menu); return true; } @override public boolean onmenuitemselected(int featureid, menuitem item) { switch(item.getitemid()) { case r.id.menu_insert: createproject(); return true; } return super.onmenuitemselected(featureid, item); } @override public void oncreatecontextmenu(contextmenu menu, view v, contextmenuinfo menuinfo) { super.oncreatecontextmenu(menu, v, menuinfo); menuinflater mi = getmenuinflater(); mi.inflate(r.menu.activity_menu_long, menu); } @override public boolean oncontextitemselected(menuitem item) { switch(item.getitemid()) { case r.id.menu_delete: adaptercontextmenuinfo info = (adaptercontextmenuinfo) item.getmenuinfo(); mdbhelper.deleteproject1(info.id); filldata(); return true; case r.id.menu_edit: adaptercontextmenuinfo info1 = (adaptercontextmenuinfo) item.getmenuinfo(); intent = new intent(this, ttsprayer.class); i.putextra(ginfydbadapter.category_column_id1, info1.id); startactivityforresult(i, activity_edit); return true; } return super.oncontextitemselected(item); } private void createproject() { intent = new intent(this, ttsprayer.class); startactivityforresult(i, activity_create); } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); cursor release = mdbhelper.fetchproject1(id); string releasename = release.getstring(release.getcolumnindexorthrow(ginfydbadapter.category_column_godname)); string releasename1 = release.getstring(release.getcolumnindexorthrow(ginfydbadapter.category_column_prayfor)); string releasename2 = release.getstring(release.getcolumnindexorthrow(ginfydbadapter.category_column_prayeeename)); list<string> godname = new arraylist<string>(arrays.aslist(releasename.split(","))); list<string> prayfor = new arraylist<string>(arrays.aslist(releasename1.split(","))); list<string> people = new arraylist<string>(arrays.aslist(releasename2.split(","))); (string temp : godname) { (string temp1 : prayfor) { (string temp2 : people) { praystring = temp +" " + temp1 +" "+ temp2 + " "; } } } typed1 = praystring; speakout(); } @override public void ondestroy() { // don't forget shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.ondestroy(); } public void oninit(int status) { if (status == texttospeech.success) { int result = tts.setlanguage(locale.us); if (result == texttospeech.lang_missing_data || result == texttospeech.lang_not_supported) { log.e("tts", "this language not supported"); } else { //btnaudioprayer.setenabled(true); speakout(); } } else { log.e("tts", "initilization failed!"); } } private void speakout() { tts.speak(typed1, texttospeech.queue_flush, null); } @override protected void onactivityresult(int requestcode, int resultcode, intent intent) { super.onactivityresult(requestcode, resultcode, intent); filldata(); }
while clicking row in list,it has produce text speech conversion,but rite didn't conversion.
looks tts in not initialized. , tabs.
add below in oncreate
tts = new texttospeech(getparent(),ttslist.this);
add @override annotation
@override public void oninit(int status)
Comments
Post a Comment