Android ListActivity でクリックされた項目の文字列表現を取得しようとしています。クリックされた項目の文字列を取得し、埋め込まれた tts サービスによって音声に変換することを目的としています。
this.getListView().setLongClickable(true);
this.getListView().setOnItemLongClickListener(新しい AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { int x=position; try{ switch (position) { case 0:startActivity(new Intent(MyActivity.this,Class.forName("Activity1"))); case 1:startActivity(new Intent(MyActivity.this,Class.forName("Acvivity2"))); case 2:startActivity(new Intent(MyActivity.this,Class.forName("Activity3"))); } return true; }catch (ClassNotFoundException e){ e.printStackTrace(); } return false; } }); setListAdapter(new ArrayAdapter<String>(MyActivity.this, R.layout.simple_list_item_1,program_names));
上記は、機能している長いクリック方法です。シングルクリックの場合、私はこのように思いますが、機能していません:
public void onListItemClick(ListView lv,View v,int pos,long id){
super.onListItemClick(lv,v,pos,id);
String selected=(String) (lv.getItemAtPosition(pos));
tts.speak(selected,TextToSpeech.QUEUE_ADD,null);
}
何が問題になる可能性がありますか?