This one should be pretty simple. The use case is that I have a ListView generated by the results of a voice search. Once the user selects the appropriate item from the list, I want the list to disappear. This list (its contents) will not be needed again. I know this can be done in a number of ways, but I am not experienced enough to know which is best (quickest, most efficient with mobile resources…etc.) I have used clearChoices(), setVisibility(2) ‘Gone’. Anyway I thought I would go to the source for a proper answer.
Thanks as always for your help. Here is the relevant code, if you like:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
mList = (ListView) findViewById(R.id.list);
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches));
mList.setTextFilterEnabled(true);
mList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String description = ((TextView) view).getText().toString();
final EditText etDesc = (EditText) findViewById(R.id.EditDescription);
etDesc.setText(description);
mList.setVisibility(2);
}
});
}
}
Well, I don’t know exactly what is what you are trying to accomplish.
You can solve this by creating a
Dialogcontaining the list, and you can either dismiss theDialogas soon as they press the item, or you can do it with an “Ok” button.Also you can separate your
activityinto two, and whenever the item is selected from the list, you finish theactivityand go back to the previousactivity.Another solution, is that once the item is selected then you do
mList.setVisibility(View.Gone)(orView.Invisibledepending on what you want to accomplish).Any of these solutions can work, and you would have to decide what works best for the logic of your app.
I hope that helps