5

I have to implement AutoComplete TextView for all the supported locales of Android Device. I tried the following:

 public class AutoCompleteView extends Activity{

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, Locales);
    AutoCompleteTextView textView = (AutoCompleteTextView)
            findViewById(R.id.locale_list);
    textView.setAdapter(adapter);
}
static Locale[] locales = Locale.getAvailableLocales();
private static final String[] Locales = ;
}

I am able to get the locales using Locale[]. In the last line of code, How to parse that to String[] Locales.. Please help me friends....

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90

1 Answers1

8

Sorry for late reply

Try this

  Locale[] locales = Locale.getAvailableLocales();
            ArrayList<String> localcountries=new ArrayList<String>();
            for(Locale l:locales)
            {
                localcountries.add(l.getDisplayLanguage().toString());
            }
    String[] languages=(String[]) localcountries.toArray(new String[localcountries.size()]);

I hope this will help you.

Pragnani
  • 20,075
  • 6
  • 49
  • 74
  • thanks. It worked for me. One more question is Can i change dynamically the Soft keyboard based on selected locale? For example, i have selected French using above code in AutoComplete TextView. After selected french, Can i dynamically change the soft keyboard to french for next EditText box??? Cani acheive that??? Please help me... – Avadhani Y Apr 02 '13 at 10:00
  • @Aʌɐpɥɐuı There is not way AFAIK, Check this for reference http://stackoverflow.com/questions/6545734/dynamically-change-android-soft-keyboard-language-setting – Pragnani Apr 02 '13 at 10:09
  • @Aʌɐpɥɐuı How ever you can change the Locale to get the resources in specific language, check this http://stackoverflow.com/questions/2900023/change-language-programatically-in-android – Pragnani Apr 02 '13 at 10:12
  • Yes, i already found that but instead of changing manually, cant we do dynamically?? – Avadhani Y Apr 02 '13 at 10:13
  • @Aʌɐpɥɐuı In same answer CommonsGuy(Mark Murphy) answered that, it is not possible. – Pragnani Apr 02 '13 at 10:22
  • In the second link which you have given, some guys says that the answers have worked for them but i tried the same. But keyboard is not changing – Avadhani Y Apr 02 '13 at 11:28
  • what i have done is created firstactivity with AutoCompleteTextView and Button. While clicking that button, i am passing the AutoCompleteTextView Value(that is selected language - Hindi) to another Activity. In the second Activity, i have editText and after loading the Activity, keyboard is not showing. Onclick of EditText the English(Default language) keyboard is showing. I have tried Alex Volovoy's answer and harikrishnan's answer.... but not working... What i have to do? I have declared the Second Activity in manifest as .. Do i need to change anymore? – Avadhani Y Apr 02 '13 at 11:32
  • @Aʌɐpɥɐuı In the Activity Tag of manifest set this android:configChanges="locale" attribute – Pragnani Apr 02 '13 at 11:36
  • Ok. For now, I thought that there is no other way to achieve this...If u found some post, please let me know.... – Avadhani Y Apr 02 '13 at 12:31