i fetching data database list view having content , button(text speech)conversion.in listview button showing , clickable function working audio not coming,the text speech audio function not working properly.
mainactivity.java
@override protected void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.activity_list_item); mdbhelper=new ginfydbadapter(mainactivity.this); mdbhelper.open(); cursor projectscursor = mdbhelper.fetchallprojects(); if(projectscursor.getcount()>0) { filldata(projectscursor); log.i("filling", "..."); } else { new getdataasynctask().execute(); } //lv1 =(listview)findviewbyid(r.id.list); //lv =(listview)findviewbyid(r.id.list); btngetselected = (button) findviewbyid(r.id.btnget); btngetselected.setonclicklistener(this); myfilter = (edittext) findviewbyid(r.id.myfilter); } private class getdataasynctask extends asynctask<void, void, void> { private progressdialog dialog = new progressdialog(mainactivity.this); protected void onpreexecute() { dialog.setmessage("loading....."); dialog.show(); } @override protected void onpostexecute(void result) { super.onpostexecute(result); /*mdbhelper=new ginfydbadapter(mainactivity.this); // initialize mdbhelper before. mdbhelper.open(); cursor projectscursor = mdbhelper.fetchallprojects(); if(projectscursor.getcount()>0) { filldata(projectscursor); }*/ for(int i=0; i<id.size(); i++){ mdbhelper=new ginfydbadapter(mainactivity.this); mdbhelper.open(); mdbhelper.savecategoryrecord(new category(id.get(i),title.get(i),content.get(i),count.get(i))); } dialog.dismiss(); } @override protected void doinbackground(void... params) { getdata(); return null; } } public void getdata() { try { httpclient httpclient = new defaulthttpclient(); httpclient.getparams().setparameter(coreprotocolpnames.protocol_version, httpversion.http_1_1); httpget request = new httpget("http://192.168.1.18:3000/api/v1/posts.json"); // httpget request = new httpget("http://gdata.youtube.com/feeds/api/users/mbbangalore/uploads?v=2&alt=jsonc"); httpresponse response = httpclient.execute(request); httpentity resentity = response.getentity(); string _response=entityutils.tostring(resentity); // content consume once log.i("................",_response); httpclient.getconnectionmanager().shutdown(); jsonobject jsonobject = new jsonobject(_response); jsonarray contacts = jsonobject.getjsonarray("post");//(url); for(int = 0; < contacts.length(); i++){ jsonobject c = contacts.getjsonobject(i); string id = c.getstring("id"); string title = c.getstring("title"); string content = c.getstring("content"); string count = c.getstring("count"); id.add(id); title.add(title); content.add(content); count.add(count); } } catch (exception e) { e.printstacktrace(); } } @suppresslint("newapi") @suppresswarnings("deprecation") private void filldata(cursor projectscursor) { //mdbhelper.open(); if(projectscursor!=null) { string[] = new string[]{ginfydbadapter.category_column_title, ginfydbadapter.category_column_content, ginfydbadapter.category_column_count}; int[] = new int[]{r.id.text2, r.id.text1, r.id.count}; dataadapter = new simplecursoradapter( this, r.layout.activity_row, projectscursor, from, to, 0); setlistadapter(dataadapter); tts = new texttospeech(this, this); final listview lv = getlistview(); lv.settextfilterenabled(true); lv.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view arg1, int position, long id) { if(arg1.getid()== r.id.btnaudioprayer && arg1.isclickable() ){ btnaudioprayer = (imagebutton) findviewbyid(r.id.btnaudioprayer); txttext = (edittext) findviewbyid(r.id.text1); toast.maketext(mainactivity.this,txttext .gettext().tostring(),toast.length_short).show(); speakout(); } } }); }else { log.i("...........","null"); } } @override public void ondestroy() { // don't forget shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.ondestroy(); } public void oninit1(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() { string text = txttext.gettext().tostring(); tts.speak(text, texttospeech.queue_flush, null); }
i followed link text speech http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/ download source code working nice,while using code in listview,that function not working properly.
Comments
Post a Comment