0

In my program, the user clicks the button, which brings a popup prompting for the user to say something. After the users says a phrase or word, the possible words listed are shown. My question is, how do I select the value selected and use it as a variable in my program.!

List View of possible values

This is my code:

public class MainActivity extends Activity {

Button listen; 
ListView lv;
static final int check = 1111;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    lv = (ListView)findViewById(R.id.listView1); 
    listen = (Button)findViewById(R.id.button2);


}


public void touched2(View v){ 
    Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.
    LANGUAGE_MODEL_FREE_FORM);
    i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak up!");
    startActivityForResult(i, check);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    if (requestCode == check && resultCode == RESULT_OK){

    ArrayList results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
    }

    super.onActivityResult(requestCode, resultCode, data); 
    }
      }

Thank you for your help in advance!

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
user2673161
  • 1,675
  • 4
  • 23
  • 28

1 Answers1

0

try accessing list view event like this

      lv.setOnItemClickListener(new ListView.OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view, int pos,
                            long id) {

     // put your logic here 
     //pos is the postion of selected item in list view

      //you can call 

     lv.getItemAtPosition(pos).toString();

    }
  });

Try this link

Community
  • 1
  • 1
Rajnish Mishra
  • 826
  • 5
  • 21