android - Show SQLite data by clicking list item in a list populated by the Database -


i have spent few days trying achieve myself , have experimented many stackoverflow answers close need achieve no avail.

i have sqlite database, each row holds holds phrase , translation phrase in foreign language, need display stored phrases in list have done far struggling figure out how 2 things when clicking list item. 2 things displaying foreign translation of clicked list item (phrase) in toast have text speech read out foreign string.

here class contains code:

public class showphrases extends activity implements oninitlistener{  private sqlitedatabase database; private cursoradapter datasource; private cursor mnotescursor; private notesdbadapter mdbhelper; private texttospeech tts; private static final string fields[] = { "phrase", basecolumns._id };//the phrase shown in list string transalation = "folang";//folang holds translation  @override public void oncreate(bundle savedinstancestate) {     this.requestwindowfeature(window.feature_no_title);     super.oncreate(savedinstancestate);     setcontentview(r.layout.hs);        notesdbadapter.databasehelper helper = new notesdbadapter.databasehelper(this);     database = helper.getwritabledatabase();     cursor data = database.query("notes", fields, null, null, null, null, null);      datasource = new simplecursoradapter(this, r.layout.highscores, data, fields, new int[]    { r.id.first });      final listview lv = (listview) findviewbyid(r.id.list_view);      lv.setheaderdividersenabled(true);     lv.addheaderview(getlayoutinflater().inflate(r.layout.highscores, null));      lv.setadapter(datasource);     lv.setclickable(true);       tts = new texttospeech(this, this);     lv.setonitemclicklistener(new adapterview.onitemclicklistener() {            @override           public void onitemclick(adapterview<?> arg0, view view, int position, long id) {           //list item shows english word when clicking need show foreign word have phone speak  //                speakout(((textview) findviewbyid(r.id.tvtranslatedtext)) //                          .gettext().tostring());                   }         });  }    @override public void oninit(int status) {     // todo auto-generated method stub     if (status == texttospeech.success) {          int result = tts.setlanguage(locale.italian);          if (result == texttospeech.lang_missing_data                 || result == texttospeech.lang_not_supported) {             log.e("tts", "this language not supported");         } else {          }      } else {         log.e("tts", "initilization failed!");     } }  private void speakout(string text) {     tts.speak(text, texttospeech.queue_flush, null); }  } 

can provide insight how can trying achieve?

you need change focusable mode of textview false

update textview in xml

android:focusable="false"   lv.setonitemclicklistener(new adapterview.onitemclicklistener() {        @override       public void onitemclick(adapterview<?> arg0, view view, int position, long id) {            data.movetoposition(position);           toast.maketext(getapplicationcontext(), c.getstring(c.getcolumnindex("notes")), toast.length_long).show();           speakout(c.getstring(c.getcolumnindex(basecolumns._id)));        }     });  

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -