2016-09-27 1 views
0

私は単純な音声認識を使用しています。最初のテキストを除く音声認識のテキストをテキスト表示で印刷します。

私は正常に動作しました。

は、私は、「備考ちょっとこれは、スタックオーバーフローされ、」私は、「備考」を除外してのTextViewのテキストの残りの部分を印刷したい

を話したとしましょう。続き

は私の仕事ですonActivityResult: -

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) 

     //If Voice recognition is successful then it returns RESULT_OK 
     if(resultCode == RESULT_OK) { 

      ArrayList<String> textMatchList = data 
        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 

      if (!textMatchList.isEmpty()) { 
       if(textMatchList.get(0).contains("Field")) 
       { 
        Intent non_field = new Intent(DashboardActivity.this,NonFieldActivity.class); 
        startActivity(non_field); 
       } 
       else if(textMatchList.get(0).contains("Tour")) 
       { 
        Intent non_field = new Intent(DashboardActivity.this,TourPlanActivity.class); 
        startActivity(non_field); 
       } 
       else { 
        final Dialog list_dialog; 
        ListView voice_match_list; 
        list_dialog = new Dialog(this); 
        list_dialog.setTitle("Matches"); 
        list_dialog.setCancelable(true); 
        list_dialog.setContentView(R.layout.voice_list_dialog); 
        voice_match_list = (ListView) list_dialog.findViewById(R.id.voice_list); 
        voice_match_list.setAdapter(new ArrayAdapter<String>(this, 
          android.R.layout.simple_list_item_1, 
          textMatchList)); 
        Button cancel_button = (Button) list_dialog.findViewById(R.id.cancel_button_voice); 
        assert cancel_button != null; 
        cancel_button.setOnClickListener(new View.OnClickListener() { 

         @Override 
         public void onClick(View v) { 

          list_dialog.dismiss(); 
         } 
        }); 
        list_dialog.show(); 
       } 

      } 
      //Result code for various error. 
     }else if(resultCode == RecognizerIntent.RESULT_AUDIO_ERROR){ 
      showToastMessage("Audio Error"); 
     }else if(resultCode == RecognizerIntent.RESULT_CLIENT_ERROR){ 
      showToastMessage("Client Error"); 
     }else if(resultCode == RecognizerIntent.RESULT_NETWORK_ERROR){ 
      showToastMessage("Network Error"); 
     }else if(resultCode == RecognizerIntent.RESULT_NO_MATCH){ 
      showToastMessage("No Match"); 
     }else if(resultCode == RecognizerIntent.RESULT_SERVER_ERROR){ 
      showToastMessage("Server Error"); 
     } 
     super.onActivityResult(requestCode, resultCode, data); 
    } 
    /** 
    * Helper method to show the toast message 
    **/ 
    void showToastMessage(String message){ 
     Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); 
    } 

Googleからの私の研究: -

.replaceは私のコードでそれを使用する方法を理解することはできません、ここに役立ちます。ある人が私に記事を提出したり、特定のロジックを教えてくれますか?

答えて

2

分割方法で行うことができます。

String message = "Remark hey this is stack overflow"; 
String [] arr = message.split(" ", 2); 

arr[0]"Remark"arr[1]"hey this is stack overflow"

が含まれていますが含まれています
関連する問題