2013-04-10 61 views
0

我正在爲視障人士製作應用程序,爲此我希望每當用戶觸摸屏幕上的任何位置時,語音識別器應該啓動。如何在整個屏幕上製作語音識別器rwork

我已經做語音識別等things..but我不能讓我的語音識別器對TouchListener工作...

TouchListener不是借活動爲視圖。應用程序崩潰

完整代碼如下。

public class MainActivity extends Activity 
{ 

private static final int REQUEST_CODE = 1234; 
private ListView wordsList; 
protected Button TextToSpeech; 
/** 
* Called with the activity is first created. 
*/ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
super.onCreate(savedInstanceState); 
setContentView(R.layout.voice_recog); 
Button speakButton = (Button) findViewById(R.id.speakButton); 
Context context; 
context = this.getApplicationContext(); 
Intent Inte = new Intent(context, FallDetection.class); 
context.startService(Inte); 
Intent Inte1 = new Intent(context, SmsSpeaker.class); 
context.startService(Inte1); 
Toast toast = Toast.makeText(getApplicationContext(), "Fall Detection Started", Toast.LENGTH_LONG); 
toast.show(); 

wordsList = (ListView) findViewById(R.id.list); 
LinearLayout myScreen = (LinearLayout) findViewById(R.id.myscreen); 
// change LinearLayout to your framelayout if it is not a LinearLayout 
//View view =(View) findViewById(R.layout.voice_recog); 

//wordsList.setOnTouchListener(new View.OnTouchListener() { 
myScreen.setOnClickListener(new OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     Toast toast = Toast.makeText(getApplicationContext(),"Touch recognised",Toast.LENGTH_LONG); 
     toast.show(); 
     startVoiceRecognitionActivity(); 
    } 
}); 

截至目前我使用清單recignizing聯繫,但與來源,也是崩潰的應用程序未發現異常

佈局XML文件如下

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myscreen" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 
+0

你的wordsList是什麼?你setOnItemClickListener? – 2013-04-10 23:14:46

+0

WordList會存儲語音識別器的結果..可能匹配的口語詞............ nope no setOnItemClickListener .. – Nirav 2013-04-10 23:21:05

回答

0

佈局XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myscreen" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 

<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:paddingBottom="4dip" 
android:text="Click the button and start speaking" /> 

<Button android:id="@+id/speakButton" 
android:layout_width="fill_parent" 
android:onClick="speakButtonClicked" 
android:layout_height="wrap_content" 
android:text="Click Me!" /> 
<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 
<ListView 
android:id="@+id/list" 
android:layout_width="fill_parent" 
android:layout_height="0dip" 
android:layout_weight="0.41" > 
</ListView> 
</ScrollView> 
</LinearLayout> 

代碼

public class MainActivity extends Activity 
{ 

    private static final int REQUEST_CODE = 1234; 
    private ListView wordsList; 
    protected Button TextToSpeech; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

     setContentView(R.layout.voice_recog); 
     Button speakButton = (Button) findViewById(R.id.speakButton); 

     Intent Inte = new Intent(this, FallDetection.class); 
     startService(Inte); 
     Intent Inte1 = new Intent(this, SmsSpeaker.class); 
     startService(Inte1); 
     Toast toast = Toast.makeText(this, "Fall Detection Started", Toast.LENGTH_LONG); 
     toast.show(); 

     wordsList = (ListView) findViewById(R.id.list); 
     LinearLayout myScreen = (LinearLayout) findViewById(R.id.myscreen); 

     myScreen.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
    // TODO Auto-generated method stub 
      Toast toast = Toast.makeText(MainActivity.this,"Touch recognised",Toast.LENGTH_LONG); 
     toast.show(); 
     startVoiceRecognitionActivity(); 
    } 
    }); 
} 
+0

thanx還......我照你說的去做了。 ..但仍然觸摸不被識別... – Nirav 2013-04-10 23:46:50

+0

我編輯了我的答案,在我的應用程序中,我做了onClick,它的工作原理。您還應該請求全屏將這些放在setContenView()requestWindowFeature(Window.FEATURE_NO_TITLE)之上的行上; \t \t \t getWindow()。addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); – 2013-04-10 23:50:02

+0

thanx Hoan ....我照你所說的做了...但它給錯誤............................. ..............方法setOnClickListener(View.OnClickListener)在類型View中不適用於參數(new OnClickListener(){}) – Nirav 2013-04-10 23:53:59