Marbles
Marbles

Reputation: 3

Menu to Select a language on start up for my app (Android SDK)

I am building my first application, I was wondering if it is possible to have the first screen prompt when the application is opened to be a menu where the user can select the language (this choice is saved), then the application is in that following language... do any tutorials exist for this?

I am using the Android SDK, with java

Upvotes: 0

Views: 63

Answers (1)

Dharmesh Dhameliya
Dharmesh Dhameliya

Reputation: 174

Write below code inside the OnCreate method if you want it pop up menu once application start

AlertDialog.Builder builderSingle = new  AlertDialog.Builder(MainActivity.this);
builderSingle.setIcon(R.drawable.ic_launcher);
builderSingle.setTitle("Select Language :-");

final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
    MainActivity.this,
    android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("English");
arrayAdapter.add("Arabian");
arrayAdapter.add("Italian");
arrayAdapter.add("French");

builderSingle.setNegativeButton(
    "cancel",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

builderSingle.setAdapter(
    arrayAdapter,
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do whatever you want to do after selection of language
        }
    });
builderSingle.show();

Upvotes: 1

Related Questions