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.github.jvanhie.discogsscrobbler.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.discogs_search, menu);
    //configure search box
    final MenuItem search = menu.findItem(R.id.search_field);
    mSearchView = (SearchView) search.getActionView();
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override// ww w.j  ava 2s.co  m
        public boolean onQueryTextSubmit(String s) {
            menu.findItem(R.id.search_field).collapseActionView();
            mLastSearch = s;
            //pass query to search fragment
            if (mSearchType > 0) {
                mSearchFragment.search(s, mSearchTypes[mSearchType]);
            } else {
                mSearchFragment.search(s);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
    mSearchView.setOnSearchClickListener(new SearchView.OnClickListener() {
        @Override
        public void onClick(View view) {
            //restore last search
            if (mLastSearch != null) {
                mSearchView.setQuery(mLastSearch, false);
            }
        }
    });
    if (mSearchType > 0) {
        mSearchView.setQueryHint("Search Discogs (" + mSearchTypes[mSearchType] + ")");
    } else {
        mSearchView.setQueryHint("Search Discogs");
    }
    //config filter spinner
    final MenuItem filter = menu.findItem(R.id.search_filter);
    Spinner s = (Spinner) filter.getActionView(); // find the spinner
    ArrayAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),
            R.array.search_filter_items, android.R.layout.simple_spinner_dropdown_item); //  create the adapter from a StringArray
    mSpinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    s.setAdapter(mSpinnerAdapter); // set the adapter
    s.setSelection(mSearchType, false);

    s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            mSearchType = i;
            PreferenceManager.getDefaultSharedPreferences(SearchActivity.this).edit()
                    .putInt(SEARCH_TYPE, mSearchType).apply();
            if (i > 0) {
                mSearchView.setQueryHint("Search Discogs (" + mSearchTypes[i] + ")");
            } else {
                mSearchView.setQueryHint("Search Discogs");
            }
            filter.collapseActionView();
            search.expandActionView();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            //filter.collapseActionView();
        }
    });
    //make sure only one actionview is expanded
    MenuItemCompat.setOnActionExpandListener(filter, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            //collapse search
            search.collapseActionView();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            //collapse filter
            filter.collapseActionView();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            return true;
        }
    });

    //only expand when the drawer is closed and initial page load
    if (!((DrawerLayout) findViewById(R.id.search_drawer_layout)).isDrawerOpen(findViewById(R.id.search_drawer))
            && !mDetailVisible) {
        search.expandActionView();
    }

    if (mSelected > 0) {

        inflater.inflate(R.menu.release_detail_search, menu);
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_lastfm", true)) {
            inflater.inflate(R.menu.release_detail_scrobble, menu);
        }
    }

    return true;
}

From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sharedialog);

    mTrackUri = getIntent().getData();/*from   ww  w  . j  av a2s .  c  o  m*/
    calculator = new StatisticsCalulator(this, new UnitsI18n(this, null));

    mFileNameView = (EditText) findViewById(R.id.fileNameField);
    mTweetView = (EditText) findViewById(R.id.tweetField);

    mShareTypeSpinner = (Spinner) findViewById(R.id.shareTypeSpinner);
    ArrayAdapter<CharSequence> shareTypeAdapter = ArrayAdapter.createFromResource(this,
            R.array.sharetype_choices, android.R.layout.simple_spinner_item);
    shareTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mShareTypeSpinner.setAdapter(shareTypeAdapter);
    mShareTargetSpinner = (Spinner) findViewById(R.id.shareTargetSpinner);

    mShareTypeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
            adjustTargetToType(position);
        }

        public void onNothingSelected(AdapterView<?> arg0) { /* NOOP */
        }
    });

    int lastType = PreferenceManager.getDefaultSharedPreferences(this).getInt(Constants.EXPORT_TYPE,
            EXPORT_TYPE_KMZ);
    mShareTypeSpinner.setSelection(lastType);
    adjustTargetToType(lastType);

    mFileNameView.setText(queryForTrackName());

    Button okay = (Button) findViewById(R.id.okayshare_button);
    okay.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            share();
        }
    });

    Button cancel = (Button) findViewById(R.id.cancelshare_button);
    cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ShareTrack.this.finish();
        }
    });
}

From source file:com.micabyte.android.app.BaseFragment.java

@SuppressWarnings("ConstantConditions")
protected Spinner setSpinner(int resId, int arrId, int sp_it, int sp_dd) {
    final Spinner s = (Spinner) getView().findViewById(resId);
    final ArrayAdapter<CharSequence> adapter = ArrayAdapter
            .createFromResource(getActivity().getApplicationContext(), arrId, sp_it);
    adapter.setDropDownViewResource(sp_dd);
    s.setAdapter(adapter);//  w  ww. ja  v a2 s  . c  o  m
    return s;
}

From source file:com.streaming.sweetplayer.fragment.CommonFragment.java

private void setupSpinner() {
    mSpinnerAdapter = ArrayAdapter.createFromResource(mActivity, R.array.genre_detail_array,
            android.R.layout.simple_spinner_item);
    mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mGenreSpinner = (Spinner) mActivity.findViewById(R.id.genre_spinner);
    mGenreSpinner.setAdapter(mSpinnerAdapter);
    mGenreSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override/*from   ww  w  .  ja v  a2 s .c  o m*/
        public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
            if (pos == 1) {
                clearListView();
                mGenreNameTextView.setVisibility(View.GONE);
                mGenreImageView.setVisibility(View.GONE);
                mGenreSpinner.setVisibility(View.GONE);
                setCommonAdapter(mGenresList);
                mCurrentTab = Config.GENRES_TAB;
            } else if (pos == 2) {
                clearListView();
                Utils.sortArrayList(mGenreArtistsList);
                setCommonAdapter(mGenreArtistsList);
            }
        }

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

        }
    });
}

From source file:org.gnucash.android.ui.export.ExportDialogFragment.java

private void bindViews() {
    View v = getView();//www.j a  va 2s . c  om
    assert v != null;
    mDestinationSpinner = (Spinner) v.findViewById(R.id.spinner_export_destination);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.export_destinations, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mDestinationSpinner.setAdapter(adapter);
    mDestinationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            View recurrenceOptionsView = getView().findViewById(R.id.recurrence_options);
            switch (position) {
            case 0:
                mExportTarget = ExportParams.ExportTarget.SD_CARD;
                recurrenceOptionsView.setVisibility(View.VISIBLE);
                break;
            case 1:
                recurrenceOptionsView.setVisibility(View.VISIBLE);
                mExportTarget = ExportParams.ExportTarget.DROPBOX;
                String dropboxAppKey = getString(R.string.dropbox_app_key, SettingsActivity.DROPBOX_APP_KEY);
                String dropboxAppSecret = getString(R.string.dropbox_app_secret,
                        SettingsActivity.DROPBOX_APP_SECRET);
                DbxAccountManager mDbxAccountManager = DbxAccountManager
                        .getInstance(getActivity().getApplicationContext(), dropboxAppKey, dropboxAppSecret);
                if (!mDbxAccountManager.hasLinkedAccount()) {
                    mDbxAccountManager.startLink(getActivity(), 0);
                }
                break;
            case 2:
                recurrenceOptionsView.setVisibility(View.VISIBLE);
                mExportTarget = ExportParams.ExportTarget.GOOGLE_DRIVE;
                SettingsActivity.mGoogleApiClient = SettingsActivity.getGoogleApiClient(getActivity());
                SettingsActivity.mGoogleApiClient.connect();
                break;
            case 3:
                mExportTarget = ExportParams.ExportTarget.SHARING;
                recurrenceOptionsView.setVisibility(View.GONE);
                break;

            default:
                mExportTarget = ExportParams.ExportTarget.SD_CARD;
                break;
            }
        }

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

        }
    });
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mExportAllCheckBox = (CheckBox) v.findViewById(R.id.checkbox_export_all);
    mExportAllCheckBox
            .setChecked(sharedPrefs.getBoolean(getString(R.string.key_export_all_transactions), false));

    mDeleteAllCheckBox = (CheckBox) v.findViewById(R.id.checkbox_post_export_delete);
    mDeleteAllCheckBox.setChecked(
            sharedPrefs.getBoolean(getString(R.string.key_delete_transactions_after_export), false));

    mSaveButton = (Button) v.findViewById(R.id.btn_save);
    mSaveButton.setText(R.string.btn_export);
    mCancelButton = (Button) v.findViewById(R.id.btn_cancel);

    mCancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    mSaveButton.setOnClickListener(new ExportClickListener());

    mRecurrenceTextView = (TextView) v.findViewById(R.id.input_recurrence);
    mRecurrenceTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            FragmentManager fm = getActivity().getSupportFragmentManager();
            Bundle b = new Bundle();
            Time t = new Time();
            t.setToNow();
            b.putLong(RecurrencePickerDialog.BUNDLE_START_TIME_MILLIS, t.toMillis(false));
            b.putString(RecurrencePickerDialog.BUNDLE_TIME_ZONE, t.timezone);

            // may be more efficient to serialize and pass in EventRecurrence
            b.putString(RecurrencePickerDialog.BUNDLE_RRULE, mRecurrenceRule);

            RecurrencePickerDialog rpd = (RecurrencePickerDialog) fm.findFragmentByTag("recurrence_picker");
            if (rpd != null) {
                rpd.dismiss();
            }
            rpd = new RecurrencePickerDialog();
            rpd.setArguments(b);
            rpd.setOnRecurrenceSetListener(ExportDialogFragment.this);
            rpd.show(fm, "recurrence_picker");
        }
    });

    mExportWarningTextView = (TextView) v.findViewById(R.id.export_warning);

    //this part (setting the export format) must come after the recurrence view bindings above
    String defaultExportFormat = sharedPrefs.getString(getString(R.string.key_default_export_format),
            ExportFormat.QIF.name());
    mExportFormat = ExportFormat.valueOf(defaultExportFormat);
    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onRadioButtonClicked(view);
        }
    };

    RadioButton ofxRadioButton = (RadioButton) v.findViewById(R.id.radio_ofx_format);
    ofxRadioButton.setOnClickListener(clickListener);
    if (defaultExportFormat.equalsIgnoreCase(ExportFormat.OFX.name())) {
        ofxRadioButton.performClick();
    }

    RadioButton qifRadioButton = (RadioButton) v.findViewById(R.id.radio_qif_format);
    qifRadioButton.setOnClickListener(clickListener);
    if (defaultExportFormat.equalsIgnoreCase(ExportFormat.QIF.name())) {
        qifRadioButton.performClick();
    }

    RadioButton xmlRadioButton = (RadioButton) v.findViewById(R.id.radio_xml_format);
    xmlRadioButton.setOnClickListener(clickListener);
    if (defaultExportFormat.equalsIgnoreCase(ExportFormat.XML.name())) {
        xmlRadioButton.performClick();
    }
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.AddProximityAlertFragment.java

/**
 * {@inheritDoc}//from  w ww . ja v a2s .c o m
 */
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Sort the distance spinner.
    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.addproxalert_distance_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(final AdapterView<?> parent, final View view, final int pos, final long id) {
            switch (pos) {
            case 0:
                meters = 100;
                break;
            case 1:
                meters = 250;
                break;
            case 2:
                meters = 500;
                break;
            case 3:
                meters = 750;
                break;
            case 4:
                meters = 1000;
                break;
            default:
                meters = 100;
                break;
            }
        }

        @Override
        public void onNothingSelected(final AdapterView parent) {
            meters = 100;
        }
    });

    // Get locality information, if there is any.
    final String locality = bsd.getLocalityForStopCode(stopCode);
    final String name;

    if (locality != null) {
        name = getString(R.string.busstop_locality_coloured, bsd.getNameForBusStop(stopCode), locality,
                stopCode);
    } else {
        name = getString(R.string.busstop_coloured, bsd.getNameForBusStop(stopCode), stopCode);
    }

    // Set the information text.
    textProxDialogStop.setText(Html.fromHtml(getString(R.string.addproxalert_second, name)));
}

From source file:com.xengar.android.englishverbs.ui.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the verb.
 *///w  ww  . j a v  a  2 s. com
private void setupSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options,
            android.R.layout.simple_spinner_item);

    // Specify dropdown layout style - simple list view with 1 item per line
    genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    // Apply the adapter to the spinner
    mRegularSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mRegularSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selection = (String) parent.getItemAtPosition(position);
            if (!TextUtils.isEmpty(selection)) {
                if (selection.equals(getString(R.string.type_regular))) {
                    mRegular = VerbEntry.REGULAR;
                } else {
                    mRegular = VerbEntry.IRREGULAR;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mRegular = VerbEntry.REGULAR;
        }
    });
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.EditTriggerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_trigger_edit, parent, false);
    setHasOptionsMenu(true);/*  w  w  w. j  a va  2s  .co  m*/

    mNoteGroup = (ViewGroup) view.findViewById(R.id.note_type_trigger_section);
    mAlertGroup = (ViewGroup) view.findViewById(R.id.alert_type_trigger_section);

    mTypeSpinner = (AppCompatSpinner) view.findViewById(R.id.trigger_type_spinner);
    ArrayAdapter<CharSequence> typeAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.trigger_type_list, android.R.layout.simple_spinner_item);
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mTypeSpinner.setAdapter(typeAdapter);

    mWhenSpinner = (AppCompatSpinner) view.findViewById(R.id.trigger_when_spinner);
    ArrayAdapter<CharSequence> whenAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.trigger_when_list, android.R.layout.simple_spinner_item);
    whenAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mWhenSpinner.setAdapter(whenAdapter);

    mValue = (EditText) view.findViewById(R.id.value_input);
    mNoteValue = (EditText) view.findViewById(R.id.trigger_note_text);
    mAudioAlert = (CheckBox) view.findViewById(R.id.alert_type_audio_selector);
    mVisualAlert = (CheckBox) view.findViewById(R.id.alert_type_visual_selector);
    mHapticAlert = (CheckBox) view.findViewById(R.id.alert_type_haptic_selector);
    if (!PermissionUtils.permissionIsGranted(getActivity(), Manifest.permission.VIBRATE)) {
        mHapticAlert.setEnabled(PermissionUtils.canRequestAgain(getActivity(), Manifest.permission.VIBRATE));
    }
    ;

    TextView unitsTextView = (TextView) view.findViewById(R.id.units);
    String units = AppSingleton.getInstance(getActivity()).getSensorAppearanceProvider()
            .getAppearance(mSensorId).getUnits(getActivity());
    unitsTextView.setText(units);

    if (!isNewTrigger()) {
        // Populate the view with the trigger's data.
        int actionType = mTriggerToEdit.getActionType();
        mValue.setText(mTriggerToEdit.getValueToTrigger().toString());
        mTypeSpinner.setSelection(actionType);
        mWhenSpinner.setSelection(mTriggerToEdit.getTriggerWhen());
        if (actionType == TriggerInformation.TRIGGER_ACTION_ALERT) {
            int[] alertTypes = mTriggerToEdit.getAlertTypes();
            for (int i = 0; i < alertTypes.length; i++) {
                int alertType = alertTypes[i];
                if (alertType == TriggerInformation.TRIGGER_ALERT_AUDIO) {
                    mAudioAlert.setChecked(true);
                } else if (alertType == TriggerInformation.TRIGGER_ALERT_VISUAL) {
                    mVisualAlert.setChecked(true);
                } else if (alertType == TriggerInformation.TRIGGER_ALERT_PHYSICAL) {
                    mHapticAlert.setChecked(true);
                }
            }
        } else if (actionType == TriggerInformation.TRIGGER_ACTION_NOTE) {
            mNoteValue.setText(mTriggerToEdit.getNoteText());
        }
        updateViewVisibilities(actionType);

        // Now add the save listeners if this is an edited trigger (not a new trigger).
        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                saveTrigger();
            }
        };
        mNoteValue.addTextChangedListener(watcher);
        mValue.addTextChangedListener(watcher);
        mWhenSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                saveTrigger();
            }

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

            }
        });
        CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                saveTrigger();
            }
        };
        mAudioAlert.setOnCheckedChangeListener(checkedChangeListener);
        mVisualAlert.setOnCheckedChangeListener(checkedChangeListener);
    } else {
        // Default to an alert spinner that triggers "at" a value, and does a visual alert.
        mTypeSpinner.setSelection(TriggerInformation.TRIGGER_ACTION_ALERT);
        mWhenSpinner.setSelection(TriggerInformation.TRIGGER_WHEN_AT);
        mVisualAlert.setChecked(true);
    }

    mWhenSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Hide all but alert types if this is a ABOVE or BELOW.
            if (position == TriggerInformation.TRIGGER_WHEN_ABOVE
                    || position == TriggerInformation.TRIGGER_WHEN_BELOW) {
                mTypeSpinner.setSelection(TriggerInformation.TRIGGER_ACTION_ALERT);
                mTypeSpinner.setEnabled(false);
                updateViewVisibilities(TriggerInformation.TRIGGER_ACTION_ALERT);
                selectAlertTypeIfNeeded();
            } else {
                mTypeSpinner.setEnabled(true);
            }
            if (!isNewTrigger()) {
                saveTrigger();
            }
        }

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

        }
    });

    mTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            updateViewVisibilities(position);
            if (position == TriggerInformation.TRIGGER_ACTION_ALERT) {
                selectAlertTypeIfNeeded();
            }
            if (!isNewTrigger()) {
                saveTrigger();
            }
        }

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

        }
    });

    mHapticAlert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // Don't let them check this checkbox if they deny the vibrate permission.
                if (!PermissionUtils.tryRequestingPermission(getActivity(), Manifest.permission.VIBRATE,
                        PERMISSION_VIBRATE, true)) {
                    mHapticAlert.setChecked(false);
                }
                ;
            }
            if (!isNewTrigger()) {
                saveTrigger();
            }
        }
    });
    return view;
}

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

public void searchButtonClicked(View view) {
    String searchString = info[0].getText().toString();

    android.util.Log.w(getClass().getSimpleName(), searchString);
    try {/*from ww w.j  a v a  2  s . c om*/
        cur = crsDB.rawQuery("select Title from Movies where Title='" + searchString + "';", new String[] {});
        android.util.Log.w(getClass().getSimpleName(), searchString);

        //If the Movie Exists in the Local Database, we will retrieve it from the Local DB
        if (cur.getCount() != 0) {
            //Raise toast message that the movie is already present in local DB
            text = " already present in DB, Retrieving..";
            Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration);
            toast.show();

            //Retrieving the Movie since we know that the movie exists in DB
            cur = crsDB.rawQuery("select Title, Genre, Years, Rated, Actors from Movies where Title = ?;",
                    new String[] { searchString });

            //Movie Already present hence disabling the Add Button
            btn.setEnabled(false);

            //Move the Cursor and set the Fields
            cur.moveToNext();
            info[1].setText(cur.getString(0));
            info[2].setText(cur.getString(1));
            info[3].setText(cur.getString(2));
            info[4].setText(cur.getString(4));

            //Set the Ratings dropdown
            if (cur.getString(3).equals("PG"))
                dropdown.setSelection(0);
            else if (cur.getString(3).equals("PG-13"))
                dropdown.setSelection(1);
            else if (cur.getString(3).equals("R"))
                dropdown.setSelection(2);
        }

        //If the Movie Does not exist in the Local Database, we will retrieve it from the OMDB
        else {
            //Movie not present in local DB, raise a toast message
            text = " being retrieved from OMDB now.";
            Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration);
            toast.show();

            //Encode the search string to be appropriate to be placed in a url
            String encodedUrl = null;
            try {
                encodedUrl = URLEncoder.encode(searchString, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                android.util.Log.e(getClass().getSimpleName(), e.getMessage());
            }

            //ASync thread running the query from OMDB and retrieving the movie details as JSON
            JSONObject result = new MovieGetInfoAsync()
                    .execute("http://www.omdbapi.com/?t=\"" + encodedUrl + "\"&r=json").get();

            //Check if the Movie query was successful
            if (result.getString("Response").equals("True")) {
                info[1].setText(result.getString("Title"));
                info[2].setText(result.getString("Genre"));
                info[3].setText(result.getString("Year"));
                info[4].setText(result.getString("Actors"));

                //Ratings field is of type Spinner class with field values (PG, PG-13, R rated)
                ArrayAdapter<CharSequence> 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);

                if (result.getString("Rated").equals("PG"))
                    dropdown.setSelection(0);
                else if (result.getString("Rated").equals("PG-13"))
                    dropdown.setSelection(1);
                else if (result.getString("Rated").equals("R"))
                    dropdown.setSelection(2);
            }
            //Search query was unsuccessful in getting movie with such a name
            else if (result.getString("Response").equals("False")) {
                //Raise a toast message
                text = " not present in OMDB, You can add it manually!";
                toast = Toast.makeText(context, "Movie " + searchString + text, duration);
                toast.show();
            }
        }
    } catch (Exception e) {
        android.util.Log.w(getClass().getSimpleName(), e.getMessage());
    }
}

From source file:io.indy.drone.activity.StrikeDetailActivity.java

private void configureActionBar() {
    // Show the Up button in the action bar.
    ActionBar actionBar = getActionBar();

    mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.locations_array,
            android.R.layout.simple_spinner_dropdown_item);

    mOnNavigationListener = new ActionBar.OnNavigationListener() {
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            onRegionSelected(itemPosition);
            return true;
        }/*from w w w . j  ava2  s . c om*/
    };

    actionBar.setTitle("");
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);

    try {
        actionBar.setSelectedNavigationItem(SQLDatabase.indexFromRegion(mRegion));
    } catch (Exception e) {
        e.printStackTrace();
    }
}