Quando aperto o botao falo o nome por exemplo potencia ele coloca o autofocus no editText, porem quando ele esta com o focus no edittext deveria apertar o botao e dizer o valor a ser escrito naquele campo, alguém me ajuda por favor.
essa é a mainActivity.java
private final int REQ_CODE_SPECH_INPUT = 100;
EditText potencia;
EditText tensao;
EditText corrente;
Button calcular;
View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private void promptSpeechInput(){
Intent it = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
it.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
it.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
it.putExtra(RecognizerIntent.EXTRA_PROMPT, "Diga Algo");
try{
startActivityForResult(it,REQ_CODE_SPECH_INPUT);
}catch (ActivityNotFoundException a){
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode,data);
switch (requestCode) {
case REQ_CODE_SPECH_INPUT: {
if(resultCode == RESULT_OK && data != null){
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String mensagem = result.get(0);
potencia = findViewById(R.id.potencia);
tensao = findViewById(R.id.tensao);
corrente = findViewById(R.id.corrente);
calcular = findViewById(R.id.calcular);
v = findViewById(R.id.view);
if(mensagem.equals("potência")){
potencia.requestFocus();
}else
if(mensagem.equals("tensão")){
tensao.requestFocus();
}else
if(mensagem.equals("corrente")){
corrente.requestFocus();
}else
if(mensagem.equals("calcular")){
}
}
}
}
}
public void Falar(View view) {
promptSpeechInput();
}
}
essa é a activit.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="79dp"
android:layout_height="wrap_content"
android:text="Potência" />
<EditText
android:id="@+id/potencia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="79dp"
android:layout_height="wrap_content"
android:text="Tensão" />
<EditText
android:id="@+id/tensao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="79dp"
android:layout_height="wrap_content"
android:text="Corrente" />
<EditText
android:id="@+id/corrente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="79dp"
android:layout_height="wrap_content"
android:text="Resistência" />
<EditText
android:id="@+id/resistencia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<Button
android:id="@+id/calcular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Microfone"
android:onClick="Falar"
/>
EditText
ganhe o foco oSpeech Recognition
seja ativado?