Hello, I am trying to get the value of a selected item in a listview. The listview consists of the names of all the countries. The problem that I encouter when running the app is that when the listview is showed, a country can be selected by typing in it's first letters. But the problem is that the position given by the callback listener onListItemClick() is the position of the new filtered list. This way the index for the array doesn't mach the list item position.
An list example: Australia Belgium Botswana Belize Where Belgium has index and position 2 -> OK after pressing BE on the keyboard the list is as follows: Belgium So the position is 1 and doesn't match the String array index any more and it results in Australia being selected. My question is how I can obtain the correct country and still use the android letter filter option because the list is otherwise quite long. My current code: package com.android.pokerwinnings; import java.util.Currency; import java.util.Locale; import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class SelectCurrency extends ListActivity { String[] countries; Locale[] ll; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ll = Locale.getAvailableLocales(); countries = new String[ll.length]; int i=0; for (Locale loc : ll) { countries[i] = loc.getDisplayCountry(); i++; } setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries)); getListView().setTextFilterEnabled(true); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Context context = getApplicationContext(); Toast.makeText(context, "Country selected: " + countries[position], Toast.LENGTH_LONG).show(); Intent intent = new Intent(SelectCurrency.this, PokerWinnings.class); startActivity(intent); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---