0

我正在尝试在 Android ListActivity 中获取单击项目的字符串表示形式。我的意图是获取单击项目的字符串,然后通过嵌入式 tts 服务将其转换为语音。通过长按每个项目来触发意图。这是我到目前为止所得到的。

this.getListView().setLongClickable(true);

this.getListView().setOnItemLongClickListener(new 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);     
 }

可能是什么问题?

4

1 回答 1

1
myList.setOnItemClickListener(onListItemClick);

private AdapterView.OnItemClickListener onListItemClick = new AdapterView.OnItemClickListener() {
@Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
......

}
于 2013-01-26T17:01:33.447 回答