Example usage for android.widget Spinner setSelection

List of usage examples for android.widget Spinner setSelection

Introduction

In this page you can find the example usage for android.widget Spinner setSelection.

Prototype

@Override
    public void setSelection(int position) 

Source Link

Usage

From source file:com.esri.arcgisruntime.sample.stretchrenderer.ParametersDialogFragment.java

/**
 * Builds parameter dialog with values pulled through from MainActivity.
 *
 * @param savedInstanceState//from  ww  w  .j  av a  2 s .  c  o  m
 * @return create parameter dialog box
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Bundle stretchParameters = getArguments();
    if (stretchParameters != null) {
        mMin = stretchParameters.getInt("min");
        mMax = stretchParameters.getInt("max");
        mPercentClipMin = stretchParameters.getInt("percent_clip_min");
        mPercentClipMax = stretchParameters.getInt("percent_clip_max");
        mStdDevFactor = stretchParameters.getInt("std_dev_factor");
        mStretchType = (MainActivity.StretchType) stretchParameters.getSerializable("stretch_type");
    }

    final AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext());
    @SuppressLint("InflateParams")
    final View dialogView = inflater.inflate(R.layout.stretch_dialog_box, null);
    paramDialog.setView(dialogView);
    paramDialog.setTitle(R.string.stretch_rendering_parameters);
    paramDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });
    paramDialog.setPositiveButton("Render", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            ParametersListener activity = (ParametersListener) getActivity();
            activity.returnParameters(mMin, mMax, mPercentClipMin, mPercentClipMax, mStdDevFactor,
                    mStretchType);
        }
    });
    // min max ui elements
    mMinTextView = (TextView) dialogView.findViewById(R.id.min_value_text_view);
    mMaxTextView = (TextView) dialogView.findViewById(R.id.max_value_text_view);
    mMinSeekBar = (SeekBar) dialogView.findViewById(R.id.min_seek_bar);
    mMaxSeekBar = (SeekBar) dialogView.findViewById(R.id.max_seek_bar);
    mMinSeekBar.setMax(255);
    mMaxSeekBar.setMax(255);
    mCurrMinTextView = (TextView) dialogView.findViewById(R.id.curr_min_text_view);
    mCurrMaxTextView = (TextView) dialogView.findViewById(R.id.curr_max_text_view);
    updateSeekBar(mMinSeekBar, mMin, mCurrMinTextView);
    updateSeekBar(mMaxSeekBar, mMax, mCurrMaxTextView);
    // percent clip ui elements
    mPercentClipMinTextView = (TextView) dialogView.findViewById(R.id.percent_clip_min_value_text_view);
    mPercentClipMaxTextView = (TextView) dialogView.findViewById(R.id.percent_clip_max_value_text_view);
    mPercentClipMinSeekBar = (SeekBar) dialogView.findViewById(R.id.percent_clip_min_seek_bar);
    mPercentClipMaxSeekBar = (SeekBar) dialogView.findViewById(R.id.percent_clip_max_seek_bar);
    mPercentClipMinSeekBar.setMax(99);
    mPercentClipMaxSeekBar.setMax(99);
    mCurrPercentClipMinTextView = (TextView) dialogView.findViewById(R.id.curr_percent_clip_min_text_view);
    mCurrPercentClipMaxTextView = (TextView) dialogView.findViewById(R.id.curr_percent_clip_max_text_view);
    updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView);
    updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView);
    // standard deviation ui elements
    mStdDevTextView = (TextView) dialogView.findViewById(R.id.std_dev_text_view);
    mStdDevSeekBar = (SeekBar) dialogView.findViewById(R.id.std_dev_seek_bar);
    mStdDevSeekBar.setMax(3);
    mCurrStdDevTextView = (TextView) dialogView.findViewById(R.id.curr_std_dev_text_view);
    updateSeekBar(mStdDevSeekBar, mStdDevFactor, mCurrStdDevTextView);
    // set ui to previous selection
    if (mStretchType == MainActivity.StretchType.MIN_MAX) {
        setMinMaxVisibility(true);
        setPercentClipVisibility(false);
        setStdDevVisibility(false);
    } else if (mStretchType == MainActivity.StretchType.PERCENT_CLIP) {
        setMinMaxVisibility(false);
        setPercentClipVisibility(true);
        setStdDevVisibility(false);
    } else if (mStretchType == MainActivity.StretchType.STANDARD_DEVIATION) {
        setMinMaxVisibility(false);
        setPercentClipVisibility(false);
        setStdDevVisibility(true);
    }
    // seek bar listeners
    mMinSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mMin = progress;
            updateSeekBar(mMinSeekBar, mMin, mCurrMinTextView);
            // move max to march min if max goes below min
            if (mMax < mMin) {
                mMax = mMin;
                updateSeekBar(mMaxSeekBar, mMax, mCurrMaxTextView);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    mMaxSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mMax = progress;
            updateSeekBar(mMaxSeekBar, mMax, mCurrMaxTextView);
            // move min to match max if min goes above max
            if (mMin > mMax) {
                mMin = mMax;
                updateSeekBar(mMinSeekBar, mMin, mCurrMinTextView);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    mPercentClipMinSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mPercentClipMin = progress;
            updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView);
            if (mPercentClipMin + mPercentClipMax > 100) {
                // constrain min + max <= 100
                mPercentClipMax = 100 - mPercentClipMin;
                updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    mPercentClipMaxSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mPercentClipMax = progress;
            updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView);
            if (mPercentClipMin + mPercentClipMax > 100) {
                // constrain min + max <= 100
                mPercentClipMin = 100 - mPercentClipMax;
                updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    mStdDevSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStdDevFactor = progress;
            updateSeekBar(mStdDevSeekBar, mStdDevFactor, mCurrStdDevTextView);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    // stretch type spinner
    List<String> stretchTypeArray = new ArrayList<>();
    stretchTypeArray.add(MainActivity.StretchType.MIN_MAX.toString()); //ordinals:0
    stretchTypeArray.add(MainActivity.StretchType.PERCENT_CLIP.toString()); //1
    stretchTypeArray.add(MainActivity.StretchType.STANDARD_DEVIATION.toString()); //2
    ArrayAdapter<String> stretchTypeSpinnerAdapter = new ArrayAdapter<>(getContext(),
            R.layout.stretch_spinner_text_view, stretchTypeArray);
    Spinner stretchTypeSpinner = (Spinner) dialogView.findViewById(R.id.stretch_type_spinner);
    stretchTypeSpinner.setAdapter(stretchTypeSpinnerAdapter);
    stretchTypeSpinner.setSelection(mStretchType.ordinal());
    stretchTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mStretchType = MainActivity.StretchType.MIN_MAX;
                setMinMaxVisibility(true);
                setPercentClipVisibility(false);
                setStdDevVisibility(false);
                break;
            case 1:
                mStretchType = MainActivity.StretchType.PERCENT_CLIP;
                setMinMaxVisibility(false);
                setPercentClipVisibility(true);
                setStdDevVisibility(false);
                break;
            case 2:
                mStretchType = MainActivity.StretchType.STANDARD_DEVIATION;
                setMinMaxVisibility(false);
                setPercentClipVisibility(false);
                setStdDevVisibility(true);
                break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    return paramDialog.create();
}

From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java

public void refreshMail() {

    JSONObject hashOptions = new JSONObject();
    if (pageNum != 1)
        JsonParser.put(hashOptions, "page_number", pageNum);
    if (filterTag != "")
        JsonParser.put(hashOptions, "tags", filterTag);

    ClientSide.setContext(getActivity());
    JSONObject result = ClientSide.send(new Object[] { hashOptions }, "/inbox", "view_inbox");

    if (result != null) {
        JSONArray messages = JsonParser.getJA(result, "messages");
        List<Map<String, String>> mailList = new ArrayList<Map<String, String>>();
        ArrayList<String> mailIds = new ArrayList<String>(24); // Max numbers on each page is 25.

        boolean hasMail = false; // By default, so that there's no way to screw up.
        if (messages.length() > 0) {
            for (int i = 0; i < messages.length(); i++) {
                JSONObject message = JsonParser.getJO(messages, i);

                Map<String, String> datum = new HashMap<String, String>(2);
                datum.put("from", JsonParser.getS(message, "from"));
                datum.put("subject", JsonParser.getS(message, "subject"));
                mailList.add(datum);//from  w  w w. j a  v a2  s  . c om

                mailIds.add(JsonParser.getS(message, "id"));

                hasMail = true;
            }
        } else {
            Map<String, String> datum = new HashMap<String, String>(2);
            datum.put("from", "No new Mail available.");
            datum.put("subject", "Sorry. :(");
            mailList.add(datum);

            hasMail = false;
        }

        // Let the UI refresh when there's no mails.
        ListView mails = (ListView) getActivity().findViewById(R.id.mails);
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), mailList, android.R.layout.simple_list_item_2,
                new String[] { "from", "subject" }, new int[] { android.R.id.text1, android.R.id.text2 });
        mails.setAdapter(adapter);

        if (hasMail == true) {
            final Object[] MAIL_IDS = mailIds.toArray();

            //spinnerReset = System.currentTimeMillis();
            mails.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> a, View v, int pos, long id) {
                    //if (System.currentTimeMillis() - spinnerReset < 1000) {
                    //Nothing!
                    //}
                    //else if (System.currentTimeMillis() - spinnerReset > 1000) {
                    String mailId = MAIL_IDS[pos].toString();

                    Intent intent = new Intent(getActivity(),
                            com.pgmacdesign.lacunacompanion.module.inbox.ViewMail.class);
                    intent.putExtra("mailId", mailId);

                    getActivity().startActivity(intent);
                    //}
                }
            });

            // Populate the pages Spinner.
            ArrayAdapter<String> pagesSpinnerAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            Spinner mailPages = (Spinner) getActivity().findViewById(R.id.mailPage);
            double pages = (double) Math.ceil(JsonParser.getL(result, "message_count") / 25);

            for (int i = 1; i < pages; i++) {
                pagesSpinnerAdapter.add("" + i);
            }

            mailPages.setAdapter(pagesSpinnerAdapter);
            mailPages.recomputeViewAttributes(mailPages);
            mailPages.setSelection(pageNum - 1);
        }
    }
}

From source file:com.fullmeadalchemist.mustwatch.ui.batch.form.BatchFormFragment.java

private void updateSpinners(Batch batch) {
    if (batch == null) {
        Timber.e("Could not update spinners because batch is null");
        return;/* w w w  .  j  a  v  a2 s. c o m*/
    }
    if (batch.outputVolume != null) {
        double volumeAmount = (double) batch.outputVolume.getValue();
        DecimalFormat f = new DecimalFormat("#.##");
        dataBinding.outputVolumeAmount.setText(f.format(volumeAmount));
        Spinner volSpin = dataBinding.outputVolumeAmountUnit;
        String unitString = getResources().getString(unitToStringResource(batch.outputVolume.getUnit()));
        volSpin.setSelection(getIndex(volSpin, unitString));

        //            volSpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        //                public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        //                    Timber.v("Volume spinner item selected: pos=%s, id=%s, string=%s", pos, id, volSpin.getItemAtPosition(pos).toString()));
        //
        //                    Object item = parent.getItemAtPosition(pos);
        //                }
        //
        //                public void onNothingSelected(AdapterView<?> parent) {
        //                }
        //            });
    }
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static void selectSpinnerItemByValue(Spinner spnr, long value) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) spnr.getAdapter();
    for (int position = 0; position < adapter.getCount(); position++) {
        if (adapter.getItemId(position) == value) {
            spnr.setSelection(position);
            return;
        }//from  w  ww  .j a v  a2s.c o m
    }
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View settingsView = getActivity().getLayoutInflater().inflate(R.layout.dialog_settings, null);

    // Initialize and set Storage Spinner adapter.
    Spinner storageSpinner = (Spinner) settingsView.findViewById(R.id.spinnerImageStorage);
    ArrayAdapter storageAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_storage_array,
            android.R.layout.simple_spinner_item);
    storageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    storageSpinner.setAdapter(storageAdapter);

    storageSpinner.setSelection(getImageStorage(getActivity()));

    storageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//w  w  w .  ja v a2s . c  o m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setImageStorage(position);
        }

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

    // Initialize and set Saved news number Spinner Adapter
    Spinner savedNewsSpinner = (Spinner) settingsView.findViewById(R.id.spinnerStoredArticlesCount);
    ArrayAdapter savedNewsAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.saved_articles_number_array, android.R.layout.simple_spinner_item);
    savedNewsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    savedNewsSpinner.setAdapter(savedNewsAdapter);

    int pos = savedNewsAdapter.getPosition(Integer.toString(getAllowedNewsCount(getActivity())));
    savedNewsSpinner.setSelection(pos);

    savedNewsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final String value = (String) parent.getItemAtPosition(position);
            setSavedNewsCount(value);
        }

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

    initImageQualityControllers(settingsView);
    initFontSizeStuff(settingsView);

    // Creates About Us Alert dialog which extends from DialogFragment.
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.settings)
            .setNeutralButton(R.string.about_us_close, null).setView(settingsView).create();
}

From source file:org.isoron.uhabits.fragments.ShowHabitFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.show_habit, container, false);
    activity = (ShowHabitActivity) getActivity();

    habit = activity.getHabit();//ww  w . j  ava2  s.c  om
    activeColor = ColorHelper.getColor(getContext(), habit.color);
    inactiveColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);

    updateHeader(view);

    dataViews = new LinkedList<>();

    Button btEditHistory = (Button) view.findViewById(R.id.btEditHistory);
    Spinner sStrengthInterval = (Spinner) view.findViewById(R.id.sStrengthInterval);

    scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);

    int defaultScoreInterval = UIHelper.getDefaultScoreInterval(getContext());
    previousScoreInterval = defaultScoreInterval;
    setScoreBucketSize(defaultScoreInterval);

    sStrengthInterval.setSelection(defaultScoreInterval);
    sStrengthInterval.setOnItemSelectedListener(this);

    dataViews.add((HabitScoreView) view.findViewById(R.id.scoreView));
    dataViews.add((HabitHistoryView) view.findViewById(R.id.historyView));
    dataViews.add((HabitFrequencyView) view.findViewById(R.id.punchcardView));
    dataViews.add((HabitStreakView) view.findViewById(R.id.streakView));

    updateHeaders(view);

    for (HabitDataView dataView : dataViews)
        dataView.setHabit(habit);

    btEditHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            HistoryEditorDialog frag = new HistoryEditorDialog();
            frag.setHabit(habit);
            frag.setListener(ShowHabitFragment.this);
            frag.show(getFragmentManager(), "historyEditor");
        }
    });

    if (savedInstanceState != null) {
        EditHabitDialogFragment fragEdit = (EditHabitDialogFragment) getFragmentManager()
                .findFragmentByTag("editHabit");
        HistoryEditorDialog fragEditor = (HistoryEditorDialog) getFragmentManager()
                .findFragmentByTag("historyEditor");

        if (fragEdit != null)
            fragEdit.setOnSavedListener(this);
        if (fragEditor != null)
            fragEditor.setListener(this);
    }

    setHasOptionsMenu(true);

    return view;
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTimeProfile.java

final static private void setSpinnerYear(final GlobalParameters mGlblParms, Dialog dialog, Spinner spinner,
        CustomSpinnerAdapter adapter, String selected) {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setPrompt(mGlblParms.context.getString(R.string.msgs_edit_profile_time_select_year));
    spinner.setAdapter(adapter);//from w w w  . j a  v a 2 s . c o m
    adapter.clear();

    String yyyy = selected.substring(0, selected.indexOf("/"));
    if (yyyy.equals("****")) {
        String tyy = sdfDate.format(System.currentTimeMillis());
        yyyy = tyy.substring(0, tyy.indexOf("/"));
    }
    int year = Integer.parseInt(yyyy);
    adapter.add(yyyy);
    adapter.add("" + (year + 1));
    spinner.setSelection(0);

}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTimeProfile.java

final static private void setSpinnerDay(final GlobalParameters mGlblParms, Dialog dialog, Spinner spinner,
        CustomSpinnerAdapter adapter, String selected) {
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setPrompt(mGlblParms.context.getString(R.string.msgs_edit_profile_time_select_day));
    spinner.setAdapter(adapter);/*from  ww  w  .  java 2 s .  c  o  m*/
    adapter.clear();

    for (int i = 1; i <= 31; i++)
        if (i > 9)
            adapter.add("" + i);
        else
            adapter.add("0" + i);
    String yyyy = selected.substring(0, selected.indexOf("/"));
    String mm = selected.replace(yyyy + "/", "").substring(0, 2);
    String dd = selected.replace(yyyy + "/" + mm + "/", "");
    if (!dd.equals("**")) {
        int day = Integer.parseInt(dd);
        spinner.setSelection(day - 1);
    } else
        spinner.setSelection(0);
}

From source file:com.bringcommunications.etherpay.SendActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overlay_frame_layout = new FrameLayout(getApplicationContext());
    setContentView(overlay_frame_layout);
    ////from   ww  w  .  j  a  v  a 2s . c o  m
    context = this;
    hex = new Hex();
    preferences = getSharedPreferences("etherpay.bringcommunications.com", MODE_PRIVATE);
    private_key = preferences.getString("key", private_key);
    acct_addr = preferences.getString("acct_addr", acct_addr);
    long wei_balance = preferences.getLong("balance", 0);
    eth_balance = (float) wei_balance / Util.WEI_PER_ETH;
    price = preferences.getFloat("price", price);
    show_gas = preferences.getBoolean("show_gas", show_gas);
    show_data = preferences.getBoolean("show_data", show_data);
    boolean denomination_eth = preferences.getBoolean("denomination_eth", true);
    System.out.println("denomination_eth is " + denomination_eth);
    denomination = denomination_eth ? Denomination.ETH : Denomination.FINNEY;
    auto_pay = getIntent().getStringExtra("AUTO_PAY");
    to_addr = getIntent().getStringExtra("TO_ADDR");
    String size_str = getIntent().getStringExtra("SIZE");
    eth_size = Float.valueOf(size_str);
    data = getIntent().getStringExtra("DATA");
    send_is_done = false;
    //
    View activity_send_view = getLayoutInflater().inflate(R.layout.activity_send, overlay_frame_layout, false);
    setContentView(activity_send_view);
    //
    Spinner dropdown = (Spinner) findViewById(R.id.denomination);
    String[] items = new String[] { "ETH", "Finney" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
            items);
    dropdown.setSelection((denomination == Denomination.ETH) ? 0 : 1);
    dropdown.setOnItemSelectedListener(this);
    dropdown.setAdapter(adapter);
    //
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    String app_name = getResources().getString(R.string.app_name);
    toolbar.setTitle(app_name);
    toolbar.setSubtitle("Send Payment");
    toolbar.setBackgroundResource(R.color.color_toolbar);
    setSupportActionBar(toolbar);
    //
    TextView to_addr_view = (TextView) findViewById(R.id.to_addr);
    to_addr_view.setText(to_addr);
    //
    TextView size_view = (TextView) findViewById(R.id.size);
    size_str = (denomination == Denomination.ETH) ? String.format("%1.03f", eth_size)
            : String.format("%03d", (int) (eth_size * 1000 + 0.5));
    size_view.setText(size_str);
    //
    LinearLayout gas_layout = (LinearLayout) findViewById(R.id.gas_layout);
    TextView gas_prompt_view = (TextView) findViewById(R.id.gas_prompt);
    TextView gas_view = (TextView) findViewById(R.id.gas);
    ImageButton gas_help_view = (ImageButton) findViewById(R.id.gas_help);
    if (show_gas) {
        String gas_str = String.format("%7d", gas_limit);
        gas_view.setText(gas_str);
        gas_layout.setVisibility(View.VISIBLE);
        gas_prompt_view.setVisibility(View.VISIBLE);
        gas_help_view.setVisibility(View.VISIBLE);
        gas_view.setVisibility(View.VISIBLE);
    } else {
        gas_layout.setVisibility(View.GONE);
        gas_prompt_view.setVisibility(View.GONE);
        gas_help_view.setVisibility(View.GONE);
        gas_view.setVisibility(View.GONE);
    }

    LinearLayout data_layout = (LinearLayout) findViewById(R.id.data_layout);
    TextView data_prompt_view = (TextView) findViewById(R.id.data_prompt);
    TextView data_view = (TextView) findViewById(R.id.data);
    ImageButton data_help_view = (ImageButton) findViewById(R.id.data_help);
    if (show_data) {
        data_view.setText(data);
        data_layout.setVisibility(View.VISIBLE);
        data_prompt_view.setVisibility(View.VISIBLE);
        data_help_view.setVisibility(View.VISIBLE);
        data_view.setVisibility(View.VISIBLE);
    } else {
        data = "";
        data_layout.setVisibility(View.GONE);
        data_prompt_view.setVisibility(View.GONE);
        data_help_view.setVisibility(View.GONE);
        data_view.setVisibility(View.GONE);
    }

    //
    //sanity check
    if (to_addr.length() != 42) {
        this.finish();
    }
}

From source file:at.bitfire.davdroid.mirakel.syncadapter.LoginURLFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.login_url, container, false);

    // protocol selection spinner
    textHttpWarning = (TextView) v.findViewById(R.id.http_warning);

    Spinner spnrScheme = (Spinner) v.findViewById(R.id.login_scheme);
    spnrScheme.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override/*from   ww w .  j av  a  2  s . co m*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            scheme = parent.getAdapter().getItem(position).toString();
            textHttpWarning.setVisibility(scheme.equals("https://") ? View.GONE : View.VISIBLE);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            scheme = null;
        }
    });
    spnrScheme.setSelection(1); // HTTPS

    // other input fields
    editBaseURI = (EditText) v.findViewById(R.id.login_host_path);
    editBaseURI.addTextChangedListener(this);

    editUserName = (EditText) v.findViewById(R.id.userName);
    editUserName.addTextChangedListener(this);

    editPassword = (EditText) v.findViewById(R.id.password);
    editPassword.addTextChangedListener(this);

    checkboxPreemptive = (CheckBox) v.findViewById(R.id.auth_preemptive);

    // hook into action bar
    setHasOptionsMenu(true);

    return v;
}