Example usage for android.widget ArrayAdapter createFromResource

List of usage examples for android.widget ArrayAdapter createFromResource

Introduction

In this page you can find the example usage for android.widget ArrayAdapter createFromResource.

Prototype

public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context,
        @ArrayRes int textArrayResId, @LayoutRes int textViewResId) 

Source Link

Document

Creates a new ArrayAdapter from external resources.

Usage

From source file:am.roadpolice.roadpolice.dialogs.DialogSettings.java

private void initUpdateIntervals(final View view) {
    Spinner spinner = (Spinner) view.findViewById(R.id.spinnerUpdateInterval);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.array_update_interval,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/* w ww. j  a va 2 s . co  m*/

    spinner.setSelection(getUpdateInterval(getActivity()));

    // Handle on click selected item listener.
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mSelectedStateOfUpdateInterval = position;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}

From source file:org.thialfihar.android.apg.ui.dialog.CreateKeyDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final FragmentActivity context = getActivity();
    final LayoutInflater mInflater;

    final int childCount = getArguments().getInt(ARG_EDITOR_CHILD_COUNT);
    mInflater = context.getLayoutInflater();

    AlertDialog.Builder dialog = new AlertDialog.Builder(context);

    View view = mInflater.inflate(R.layout.create_key_dialog, null);
    dialog.setView(view);//from  w w  w.j  a  va 2 s. c o  m
    dialog.setTitle(R.string.title_create_key);

    boolean wouldBeMasterKey = (childCount == 0);

    final Spinner algorithm = (Spinner) view.findViewById(R.id.create_key_algorithm);
    ArrayList<Choice> choices = new ArrayList<Choice>();
    choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString(R.string.dsa)));
    if (!wouldBeMasterKey) {
        choices.add(new Choice(Id.choice.algorithm.elgamal, getResources().getString(R.string.elgamal)));
    }

    choices.add(new Choice(Id.choice.algorithm.rsa, getResources().getString(R.string.rsa)));

    ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(context, android.R.layout.simple_spinner_item,
            choices);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    algorithm.setAdapter(adapter);
    // make RSA the default
    for (int i = 0; i < choices.size(); ++i) {
        if (choices.get(i).getId() == Id.choice.algorithm.rsa) {
            algorithm.setSelection(i);
            break;
        }
    }

    final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size);
    ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(context,
            R.array.key_size_spinner_values, android.R.layout.simple_spinner_item);
    keySizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    keySize.setAdapter(keySizeAdapter);
    keySize.setSelection(3); // Default to 4096 for the key length
    dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int id) {
            di.dismiss();
            try {
                int nKeyIndex = keySize.getSelectedItemPosition();
                switch (nKeyIndex) {
                case 0:
                    mNewKeySize = 512;
                    break;
                case 1:
                    mNewKeySize = 1024;
                    break;
                case 2:
                    mNewKeySize = 2048;
                    break;
                case 3:
                    mNewKeySize = 4096;
                    break;
                }
            } catch (NumberFormatException e) {
                mNewKeySize = 0;
            }

            mNewKeyAlgorithmChoice = (Choice) algorithm.getSelectedItem();
            mAlgorithmSelectedListener.onAlgorithmSelected(mNewKeyAlgorithmChoice, mNewKeySize);
        }
    });

    dialog.setCancelable(true);
    dialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int id) {
            di.dismiss();
        }
    });

    return dialog.create();
}

From source file:org.onebusaway.android.ui.ReportTripProblemFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Set the stop name.
    Bundle args = getArguments();//from   w  w w . j a  v a2s  . co  m
    final TextView tripName = (TextView) view.findViewById(R.id.trip_name);
    tripName.setText(MyTextUtils.toTitleCase(args.getString(TRIP_NAME)));

    // TODO: Switch this based on the trip mode
    final int tripArray = R.array.report_trip_problem_code_bus;

    //
    // The code spinner
    //
    mCodeView = (Spinner) view.findViewById(R.id.report_problem_code);
    ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(getActivity(), tripArray,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCodeView.setAdapter(adapter);

    // Comment
    mUserComment = (TextView) view.findViewById(R.id.report_problem_comment);

    // On vehicle
    mUserOnVehicle = (CheckBox) view.findViewById(R.id.report_problem_onvehicle);
    final View label = view.findViewById(R.id.report_problem_uservehicle_label);
    mUserVehicle = (TextView) view.findViewById(R.id.report_problem_uservehicle);
    // Disabled by default
    label.setEnabled(false);
    mUserVehicle.setEnabled(false);

    mUserOnVehicle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean checked = mUserOnVehicle.isChecked();
            label.setEnabled(checked);
            mUserVehicle.setEnabled(checked);
        }
    });

    if (savedInstanceState != null) {
        int position = savedInstanceState.getInt(CODE);
        mCodeView.setSelection(position);

        CharSequence comment = savedInstanceState.getCharSequence(USER_COMMENT);
        mUserComment.setText(comment);

        boolean onVehicle = savedInstanceState.getBoolean(USER_ON_VEHICLE);
        mUserOnVehicle.setChecked(onVehicle);

        CharSequence num = savedInstanceState.getCharSequence(USER_VEHICLE_NUM);
        mUserVehicle.setText(num);
        mUserVehicle.setEnabled(onVehicle);
    }

    SPINNER_TO_CODE = new String[] { null, ObaReportProblemWithTripRequest.VEHICLE_NEVER_CAME,
            ObaReportProblemWithTripRequest.VEHICLE_CAME_EARLY,
            ObaReportProblemWithTripRequest.VEHICLE_CAME_LATE, ObaReportProblemWithTripRequest.WRONG_HEADSIGN,
            ObaReportProblemWithTripRequest.VEHICLE_DOES_NOT_STOP_HERE, ObaReportProblemWithTripRequest.OTHER };
}

From source file:net.alchemiestick.katana.winehqappdb.filter_dialog.java

private void setupSpinner(int spId, int arrayId, String cur, AdapterView.OnItemSelectedListener listener) {
    Spinner sp = (Spinner) findViewById(spId);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(cx, arrayId,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp.setAdapter(adapter);//from   w w w.j ava 2 s . c o  m
    int pos = adapter.getPosition(cur);
    sp.setSelection(pos);
    sp.setOnItemSelectedListener(listener);
}

From source file:com.hilllander.naunginlecalendar.view.activity.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    View tbShadow = findViewById(R.id.home_toolbar_shadow);
    Util.hideToolBarShadowForLollipop(this, toolbar, tbShadow);
    mainLayout = (LinearLayout) findViewById(R.id.main_layout);
    Util.setStatusBarPaddingForKitkat(this, mainLayout);
    setSupportActionBar(toolbar);/*w  ww .j  a  va2 s  .  co  m*/
    Util.setSystemUiVisibilityForKitkat(this);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.spinner_item,
            android.R.layout.simple_spinner_item);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(arrayAdapter);
    spinner.setOnItemSelectedListener(new SpinnerListener());
    GregorianCalendar today = new GregorianCalendar();
    setCurrentDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
    detecter = new SimpleGestureFilter(this, this);

}

From source file:net.dian1.player.activity.RadioActivity.java

/** Called when the activity is first created. */
@Override/*from   w  ww.j a  v  a2  s.  c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.search);

    mRadioListView = (ListView) findViewById(R.id.SearchListView);
    mRadioAdapter = new RadioAdapter(this);
    mRadioListView.setAdapter(mRadioAdapter);
    mRadioListView.setOnItemClickListener(mRadioListListener);
    mButton = (Button) findViewById(R.id.SearchButton);
    mButton.setText(R.string.radio);
    mButton.setOnClickListener(mButtonClickListener);
    mEditText = (EditText) findViewById(R.id.SearchEditText);
    mViewFlipper = (ViewFlipper) findViewById(R.id.SearchViewFlipper);

    mSpinner = (Spinner) findViewById(R.id.SearchSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.radio_modes,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(adapter);
    mEditText.setHint(R.string.radio_hint);

    mRadioLoadingDialog = new RadioLoadingDialog(this, R.string.loading_recomended_radios,
            R.string.failed_recomended_radios);

    mRadioLoadingDialog.execute();

    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
            switch (position) {
            case 0:
                // recent
                mRadioAdapter.setList(new DatabaseImpl(RadioActivity.this).getRecentRadios(20));
                break;
            case 1:
                // recommended
                switch (mRadioLoadingDialog.getStatus()) {
                case RUNNING:
                    break;
                case FINISHED:
                    mRadioLoadingDialog = new RadioLoadingDialog(RadioActivity.this,
                            R.string.loading_recomended_radios, R.string.failed_recomended_radios);
                    mRadioLoadingDialog.execute();
                    break;
                case PENDING:
                    mRadioLoadingDialog.execute();
                    break;
                }
                break;

            default:
                break;
            }

            setupListView();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    // TODO (maybe) if recent.count > 0 set to recent
    mSpinner.setSelection(1);

    mGestureOverlayView = (GestureOverlayView) findViewById(R.id.gestures);
    mGestureOverlayView.addOnGesturePerformedListener(Dian1Application.getInstance().getPlayerGestureHandler());
}

From source file:com.example.accountkitsample.MainActivity.java

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

    if (AccountKit.getCurrentAccessToken() != null) {
        showHelloActivity(null);//from  ww  w .  ja v a2s  .com
    }

    final Spinner themeSpinner = (Spinner) findViewById(R.id.theme_spinner);
    if (themeSpinner != null) {
        final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.theme_options,
                android.R.layout.simple_spinner_dropdown_item);
        themeSpinner.setAdapter(adapter);
        themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(final AdapterView<?> parent, final View view, final int position,
                    final long id) {
                switch (position) {
                case 0:
                    selectedThemeId = R.style.AppLoginTheme;
                    break;
                case 1:
                    selectedThemeId = R.style.AppLoginTheme_Salmon;
                    break;
                case 2:
                    selectedThemeId = R.style.AppLoginTheme_Yellow;
                    break;
                case 3:
                    selectedThemeId = R.style.AppLoginTheme_Red;
                    break;
                case 4:
                    selectedThemeId = R.style.AppLoginTheme_Dog;
                    break;
                case 5:
                    selectedThemeId = R.style.AppLoginTheme_Bicycle;
                    break;
                case 6:
                    selectedThemeId = R.style.AppLoginTheme_Reverb_A;
                    advancedUISwitch.setChecked(true);
                    break;
                case 7:
                    selectedThemeId = R.style.AppLoginTheme_Reverb_B;
                    advancedUISwitch.setChecked(true);
                    break;
                case 8:
                    selectedThemeId = R.style.AppLoginTheme_Reverb_C;
                    advancedUISwitch.setChecked(true);
                    break;
                default:
                    selectedThemeId = -1;
                    break;
                }
            }

            @Override
            public void onNothingSelected(final AdapterView<?> parent) {
                selectedThemeId = -1;
            }
        });
    }

    advancedUISwitch = (Switch) findViewById(R.id.advanced_ui_switch);

    final MainActivity thisActivity = this;
    final LinearLayout advancedUIOptionsLayout = (LinearLayout) findViewById(R.id.advanced_ui_options);

    final List<CharSequence> buttonNames = new ArrayList<>();
    buttonNames.add("Default");
    for (ButtonType buttonType : ButtonType.values()) {
        buttonNames.add(buttonType.name());
    }
    final ArrayAdapter<CharSequence> buttonNameAdapter = new ArrayAdapter<>(thisActivity,
            android.R.layout.simple_spinner_dropdown_item, buttonNames);

    advancedUISwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                advancedUIOptionsLayout.setVisibility(View.VISIBLE);

                final Spinner entryButtonSpinner = (Spinner) findViewById(R.id.entry_button_spinner);
                if (entryButtonSpinner != null) {
                    entryButtonSpinner.setAdapter(buttonNameAdapter);
                    entryButtonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(final AdapterView<?> parent, final View view,
                                final int position, final long id) {
                            // First position is empty, so anything past that
                            if (position > 0) {
                                entryButton = ButtonType
                                        .valueOf(entryButtonSpinner.getSelectedItem().toString());
                            } else {
                                entryButton = null;
                            }
                        }

                        @Override
                        public void onNothingSelected(final AdapterView<?> parent) {
                            entryButton = null;
                        }
                    });
                }

                final Spinner confirmButtonSpinner = (Spinner) findViewById(R.id.confirm_button_spinner);
                if (confirmButtonSpinner != null) {
                    confirmButtonSpinner.setAdapter(buttonNameAdapter);
                    confirmButtonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(final AdapterView<?> parent, final View view,
                                final int position, final long id) {
                            // First position is empty, so anything past
                            // that
                            if (position > 0) {
                                confirmButton = ButtonType
                                        .valueOf(confirmButtonSpinner.getSelectedItem().toString());
                            } else {
                                confirmButton = null;
                            }
                        }

                        @Override
                        public void onNothingSelected(final AdapterView<?> parent) {
                            confirmButton = null;
                        }
                    });
                }

                final Spinner textPositionSpinner = (Spinner) findViewById(R.id.text_position_spinner);
                if (textPositionSpinner != null) {
                    final List<CharSequence> textPositions = new ArrayList<>();
                    textPositions.add("Default");
                    for (TextPosition textPosition : TextPosition.values()) {
                        textPositions.add(textPosition.name());
                    }
                    final ArrayAdapter<CharSequence> textPositionAdapter = new ArrayAdapter<>(thisActivity,
                            android.R.layout.simple_spinner_dropdown_item, textPositions);

                    textPositionSpinner.setAdapter(textPositionAdapter);
                    textPositionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(final AdapterView<?> parent, final View view,
                                final int position, final long id) {
                            // First position is empty, so anything past
                            // that
                            if (position > 0) {
                                textPosition = TextPosition
                                        .valueOf(textPositionSpinner.getSelectedItem().toString());
                            } else {
                                textPosition = null;
                            }
                        }

                        @Override
                        public void onNothingSelected(final AdapterView<?> parent) {
                            textPosition = null;
                        }
                    });
                }
            } else if (isReverbThemeSelected()) {
                advancedUISwitch.setChecked(true);
                Toast.makeText(MainActivity.this, R.string.reverb_advanced_ui_required, Toast.LENGTH_LONG)
                        .show();
            } else {
                advancedUIOptionsLayout.setVisibility(View.GONE);
            }
        }
    });
}

From source file:org.droidpres.activity.TransferActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.transfer);//from  w w w  .  ja v a  2 s  .c  o  m

    cf = SetupRootActivity.getCurrencyFormat(this);

    mBtExport = (Button) findViewById(R.id.btExport);
    mBtImport = (Button) findViewById(R.id.btImport);
    mTvTrLog = (TextView) findViewById(R.id.tvTransferLog);
    mSpNetType = (Spinner) findViewById(R.id.spNetType);

    mBtImport.setOnClickListener(this);
    mBtExport.setOnClickListener(this);

    mDataBase = DB.get().getWritableDatabase();

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.itemNetType,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpNetType.setAdapter(adapter);

    mAgentId = Integer.parseInt(SetupRootActivity.getAgentID(this));
}

From source file:com.android.applications.todoist.views.SupportForm.java

private void initControls() {
    //URI of the XMLRPC Server-Side Script
    this.uri = URI.create("http://dev.drewdahl.com/server.php");
    this.client = new XMLRPCClient(uri);

    this.nameText = (EditText) findViewById(R.id.EditText_Name);
    this.emailText = (EditText) findViewById(R.id.EditText_Email);
    this.problemText = (EditText) findViewById(R.id.EditText_Problem);
    this.areaSpinner = (Spinner) findViewById(R.id.Spinner_Area);
    this.submitButton = (Button) findViewById(R.id.Button_Submit);

    //Call rpcCall() on button click
    this.submitButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View view) {
            rpcCall();/* w  w w.  ja  v  a2  s  . c o m*/
        }
    });

    m_adapterForSpinner = ArrayAdapter.createFromResource(this, R.array.support_areas,
            android.R.layout.simple_spinner_item);
    m_adapterForSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    areaSpinner.setAdapter(m_adapterForSpinner);
    /*areaSpinner.setOnItemSelectedListener(
    new OnItemSelectedListener() {
               
       @Override
       public void onItemSelected(AdapterView<?> parent, View view,
             int position, long id) {
          //Do Nothing
       }
            
       @Override
       public void onNothingSelected(AdapterView<?> parent) {
          //Do Nothing
       }
               
    });*/
}