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:com.example.weiranfang.healthmonitoranalysis2014.HeatMapActivity.java

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -95), 2.8f));

    // Set up the spinner/dropdown list
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);//from  w w  w.  jav  a2s  . c  om
    spinner.setOnItemSelectedListener(new SpinnerActivity());

    try {
        JSONArray jsonArray = new GenerateJSONArrayTask().execute(new JSONSender()).get();
        mLists.put(getString(R.string.tweet_heat_map),
                new DataSet(readItems(jsonArray), getString(R.string.police_stations_url)));
        mLists.put(getString(R.string.medicare),
                new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    // Make the handler deal with the map
    // Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
    // intensity from, and the map to draw the heatmap on
    // radius, gradient and opacity not specified, so default are used
}

From source file:com.android.medisolv.RegistrationActivity.java

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

    mobile = (EditText) findViewById(R.id.mobile_no);

    firstName = (EditText) findViewById(R.id.reg_fn);
    lastName = (EditText) findViewById(R.id.reg_ln);
    email = (EditText) findViewById(R.id.reg_email);
    mobile = (EditText) findViewById(R.id.reg_mobile);

    /*code to set date picker*/
    dateFormatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
    dob = (EditText) findViewById(R.id.reg_dob);
    addListenerOnButton();//from  w w w.  ja v  a 2  s. com

    /*code to set custom title bar*/
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);

    /*set spinner values*/
    spinner = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(this, R.array.spinner1_array,
            R.layout.support_simple_spinner_dropdown_item);
    spinner.setAdapter(arrayAdapter);

    /*set gender spinner values*/
    genderSpinner = (Spinner) findViewById(R.id.genderSpinner);
    ArrayAdapter genderArrayAdapter = ArrayAdapter.createFromResource(this, R.array.gender_array,
            R.layout.support_simple_spinner_dropdown_item);
    genderSpinner.setAdapter(genderArrayAdapter);

    /* set Registration Type spinner values*/
    regTypeSpinner = (Spinner) findViewById(R.id.regTypeSpinner);
    ArrayAdapter regTypeArrayAdapter = ArrayAdapter.createFromResource(this, R.array.regType_array,
            R.layout.support_simple_spinner_dropdown_item);
    regTypeSpinner.setAdapter(regTypeArrayAdapter);

    spinner.setOnItemSelectedListener(this);
    genderSpinner.setOnItemSelectedListener(this);
    regTypeSpinner.setOnItemSelectedListener(this);

    submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v) {

            String enteredFirstName = firstName.getText().toString();

            String enteredLastName = lastName.getText().toString();

            String name = enteredFirstName + " " + enteredLastName;

            String enteredEmail = email.getText().toString().trim();

            String enteredMobile = mobile.getText().toString();

            String selectedGender = genderSpinner.getSelectedItem().toString();

            String enteredDob = dob.getText().toString();

            String selectedRegType = regTypeSpinner.getSelectedItem().toString();

            String enteredLicense = license.getText().toString();

            String enteredSpecialization = specialisation.getText().toString();

            String salute = spinner.getSelectedItem().toString();

            String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";

            String changedFormatDob = "";

            try {
                Date dobDate = dateFormatter.parse(enteredDob);
                changeDateFormatter = new SimpleDateFormat("yyyy/mm/dd", Locale.UK);
                changedFormatDob = changeDateFormatter.format(dobDate);
                System.out.println("Changed date: " + changedFormatDob);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            if (enteredFirstName.equals("") || enteredLastName.equals("") || enteredEmail.equals("")
                    || enteredMobile.equals("") || selectedGender.equals("") || selectedRegType.equals("")
                    || changedFormatDob.equals("") || salute.equals("") || enteredEmail.equals("")) {

                Toast.makeText(RegistrationActivity.this, "All fields are mandatory", Toast.LENGTH_LONG).show();

                return;

            } else if (selectedRegType.equals("Doctor")
                    && (enteredLicense.equals("") || enteredSpecialization.equals(""))) {

                Toast.makeText(RegistrationActivity.this, "All fields are mandatory", Toast.LENGTH_LONG).show();

                return;

            } else if (enteredMobile.length() < 10) {
                Toast.makeText(RegistrationActivity.this, "Mobile Number should be 10 digits",
                        Toast.LENGTH_LONG).show();
                return;
            }

            else if (enteredEmail.matches(emailPattern) == false) {
                System.out.println("Invalid Email");
                Toast.makeText(RegistrationActivity.this, "Please enter the valid Email Address",
                        Toast.LENGTH_LONG).show();
                return;
            }
            // request authentication with remote server4
            else {
                RegistrationActivityAsyncTask asyncRequestObject = new RegistrationActivityAsyncTask();

                asyncRequestObject.execute(serverUrl, salute, name, enteredMobile, enteredEmail, selectedGender,
                        changedFormatDob, selectedRegType, enteredLicense, enteredSpecialization);
            }
        }

    });

}

From source file:com.amagi82.kerbalspaceapp.Settings.java

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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    getActionBar().setTitle(R.string.title_activity_settings);

    SeekBar clearance = (SeekBar) findViewById(R.id.seekBarClearance);
    SeekBar margins = (SeekBar) findViewById(R.id.seekBarMargins);
    SeekBar inclination = (SeekBar) findViewById(R.id.seekBarInclination);
    mClearance = (TextView) findViewById(R.id.tvClearance);
    mMargins = (TextView) findViewById(R.id.tvMargins);
    mInclination = (TextView) findViewById(R.id.tvInclination);
    chooseLanguage = (Spinner) findViewById(R.id.spinnerLanguages);

    SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
    mClearanceValue = prefs.getInt("mClearanceValue", 1000);
    mMarginsValue = prefs.getInt("mMarginsValue", 10);
    mInclinationValue = prefs.getInt("mInclinationValue", 30);
    chooseLanguage.setSelection(prefs.getInt("language", 0));

    // Set up spinner
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActionBar().getThemedContext(),
            R.array.languages, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    chooseLanguage.setAdapter(adapter);//from   w  w w  .j  a va2  s .c o m
    // @formatter:off
    if (Locale.getDefault().getLanguage().equals("en"))
        chooseLanguage.setSelection(0);
    if (Locale.getDefault().getLanguage().equals("fr"))
        chooseLanguage.setSelection(1);
    if (Locale.getDefault().getLanguage().equals("de"))
        chooseLanguage.setSelection(2);
    if (Locale.getDefault().getLanguage().equals("es"))
        chooseLanguage.setSelection(3);
    if (Locale.getDefault().getLanguage().equals("ru"))
        chooseLanguage.setSelection(4);

    // Set seekbar progress
    clearance.setProgress(mClearanceValue);
    margins.setProgress(mMarginsValue);
    inclination.setProgress(mInclinationValue);

    // Display values
    mClearance.setText(mClearanceValue + "m");
    mMargins.setText(mMarginsValue + "%");
    setInclinationText();

    clearance.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            String value = NumberFormat.getNumberInstance(Locale.getDefault()).format(progress);
            mClearance.setText(value + "m");
            mClearanceValue = progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    margins.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mMargins.setText(progress + "%");
            mMarginsValue = progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    inclination.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mInclinationValue = progress;
            setInclinationText();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    chooseLanguage.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            language = langCode[chooseLanguage.getSelectedItemPosition()];
            onConfigurationChanged(getResources().getConfiguration());
        }

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

}

From source file:free.rm.skytube.gui.fragments.VideosGridFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(),
                R.array.video_categories, android.R.layout.simple_spinner_dropdown_item);

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setListNavigationCallbacks(spinnerAdapter, this);
    }/*  w w  w.  j  a va  2  s .c  om*/

    subsDrawerToggle.syncState();
}

From source file:org.chromium.latency.walt.AudioFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    logger = SimpleLogger.getInstance(getContext());

    audioTest = new AudioTest(getActivity());
    audioTest.setTestStateListener(this);

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_audio, container, false);
    textView = (TextView) view.findViewById(R.id.txt_box_audio);
    textView.setMovementMethod(new ScrollingMovementMethod());
    startButton = view.findViewById(R.id.button_start_audio);
    stopButton = view.findViewById(R.id.button_stop_audio);
    chartLayout = view.findViewById(R.id.chart_layout);
    chart = (LineChart) view.findViewById(R.id.chart);
    latencyChart = (HistogramChart) view.findViewById(R.id.latency_chart);

    view.findViewById(R.id.button_close_chart).setOnClickListener(this);
    enableButtons();//from   w  w  w .  j  a v a  2  s.  c  o  m

    // Configure the audio mode spinner
    modeSpinner = (Spinner) view.findViewById(R.id.spinner_audio_mode);
    ArrayAdapter<CharSequence> modeAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.audio_mode_array, android.R.layout.simple_spinner_item);
    modeAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    modeSpinner.setAdapter(modeAdapter);

    return view;
}

From source file:edu.asu.msse.sgowdru.moviemediaplayerrpc.SearchMovie.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_movie);
    //Collect the intent object with parameters sent from the caller
    intent = getIntent();//from   w  w w .  j av a2  s.c o  m

    info = new TextView[5];
    //In the info array of TextView type store id of each field
    info[0] = (TextView) findViewById(R.id.autoCompleteTextView);
    info[1] = (TextView) findViewById(R.id.editTitleSearch);
    info[2] = (TextView) findViewById(R.id.editGenreSearch);
    info[3] = (TextView) findViewById(R.id.editYearSearch);
    info[4] = (TextView) findViewById(R.id.editActorsSearch);

    //Ratings field is of type Spinner class with field values (PG, PG-13, R rated)
    dropdown = (Spinner) findViewById(R.id.spinnerSearch);
    adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dropdown.setAdapter(adapter);

    addButton = (Button) findViewById(R.id.addSearch);

    //Set the Video player ID, initially set the visibility to NONE
    playButton = (Button) findViewById(R.id.play);
    playButton.setVisibility(View.GONE);

    //There is no file available to play by default
    videoFile = null;

    context = getApplicationContext();
    duration = Toast.LENGTH_SHORT;

    db = new MoviesDB(this);
    try {
        crsDB = db.openDB();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, gen);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.editGenreSearch);
    textView.setAdapter(adapter);

}

From source file:can.yrt.onebusaway.ReportTripProblemFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Set the stop name.
    Bundle args = getArguments();/*from w  ww.j av a2  s  .  com*/
    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);
    }
}

From source file:com.armtimes.dialogs.DialogSettings.java

/**
 * This function initialize News Preview Font Size Spinner and
 * it's adapter./*from   www .  ja v a  2 s  . c  o  m*/
 *
 * @param settingsView Settings view with controllers.
 */
private void initFontSizeStuff(final View settingsView) {
    Spinner fontSizeSpinner = (Spinner) settingsView.findViewById(R.id.spinnerFontSize);
    // Initialize Adapter
    ArrayAdapter fontSizeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.font_size_array,
            android.R.layout.simple_spinner_item);
    fontSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fontSizeSpinner.setAdapter(fontSizeAdapter);

    int selectedItem = 0;
    switch (getTextFontSize(getActivity())) {
    case android.R.style.TextAppearance_Medium:
        selectedItem = 1;
        break;
    case android.R.style.TextAppearance_Large:
        selectedItem = 2;
        break;
    }

    fontSizeSpinner.setSelection(selectedItem);

    fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setTextFontSize(position == 1 ? android.R.style.TextAppearance_Medium
                    : position == 2 ? android.R.style.TextAppearance_Large
                            : android.R.style.TextAppearance_Small);
        }

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

From source file:com.example.android.popularmovies.app.MovieListingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    movies = new ArrayList<MovieDetails>();

    movieAdapter = new MovieArrayAdapter(getActivity(), // The current context (this activity)
            R.layout.list_item_listing, // The name of the layout ID.
            R.id.list_item_listing_textview, // The ID of the textview to populate.
            movies);//  w  w w. j  a  v  a2  s .co  m

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    Spinner spinner = (Spinner) rootView.findViewById(R.id.sort_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.sort_options,
            android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);

    FetchMovieListingTask movieListingTask = new FetchMovieListingTask();
    movieListingTask.execute(String.valueOf(spinner.getSelectedItemPosition()));

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            FetchMovieListingTask movieListingTask = new FetchMovieListingTask();
            movieListingTask.execute(String.valueOf(i));
        }

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

        }
    });

    // Get a reference to the ListView, and attach this adapter to it.
    GridView gridView = (GridView) rootView.findViewById(R.id.grid_view_listing);
    gridView.setAdapter(movieAdapter);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            // Log.i("MovieListingFragment", "Item clicked: " + view.toString() + " " + i + " " + l);
            getActivity().getSupportFragmentManager().beginTransaction().addToBackStack(null)
                    .replace(R.id.container, MovieDetailsFragment.newInstance(movies.get(i).id))
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit();
        }
    });

    return rootView;
}

From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_notification);
    mHandler = new Handler();

    lvPackages = (ListView) findViewById(R.id.listPackages);
    spMode = (Spinner) findViewById(R.id.spMode);
    tvTaskerNotice = (TextView) findViewById(R.id.tvTaskerNotice);
    findViewById(R.id.tvAccessibilityError).setOnClickListener(new OnClickListener() {
        @Override//from w  ww .jav a  2s. c  om
        public void onClick(View v) {
            startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
        }
    });

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.mode_choices,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spMode.setAdapter(adapter);
    spMode.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            mMode = Constants.Mode.values()[pos];
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mMode = Constants.Mode.OFF;
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Mode is: off");
            }
        }
    });

}