Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

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

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_pnr_status);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("PNR Status");
    mUtil = Util.getUtil(this);
    mBtnPNR = ((Button) findViewById(R.id.id_btn_get_pnr_sts));
    mBtnPNR.setOnClickListener(this);
    pnrDB = PNRDatabase.getPNRDatabase(this);
    mPNRList = new ArrayList<String>();
    mPNRList = pnrDB.getPNRs();//  w ww.ja  v  a  2 s. c o  m
    mACTPNR = (AutoCompleteTextView) findViewById(R.id.id_act_pnr_sts);
    mACTPNR.setAdapter(new ArrayAdapter<String>(this, R.layout.layout_dropdown_list, mPNRList));
    mPref = PreferenceManager.getDefaultSharedPreferences(this);
    isWaitingList = false;

    if (savedInstanceState != null) {
        if (!mPNRNumber.equals("")) {
            if (!mUtil.isConnected()) {
                mFrameLayout = null;
                mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);
                readAndShowOfflinePNRStatus();
                return;
            }
            mFrameLayout = null;
            mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);

            mPassengerDetails = savedInstanceState.getParcelable("PSN");
            mTrainDetails = savedInstanceState.getParcelable("TRAIN");
            mPageResult = savedInstanceState.getString("PAGE");
            if (mPageResult == null) {
                return;
            }

            mTextViewPNRSts = null;
            mTextViewPNRSts = new TextView(mActivity);
            mTextViewPNRSts.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            mTextViewPNRSts.setGravity(Gravity.CENTER_HORIZONTAL);
            mTextViewPNRSts.setTextColor(Color.RED);

            createTableLayoutTrnDtls();
            createTableLayoutPsnDtls();
            try {
                combineTrainAndPsnDetails();
            } catch (Exception e) {
                Log.e("PNRStat Error:", "Error creating table layout. Please try again later!");
            }
            return;
        }
    }

    mActivity = this;
    mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);
    mBtnPNR = ((Button) findViewById(R.id.id_btn_get_pnr_sts));
    mBtnPNR.setOnClickListener(this);
    mTextViewPNRSts = new TextView(mActivity);
    mTextViewPNRSts.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mTextViewPNRSts.setGravity(Gravity.CENTER_HORIZONTAL);
    mTextViewPNRSts.setTextColor(Color.RED);
}

From source file:fr.cph.stock.android.activity.OverallActivity.java

private void showPanelUpdateHistory() {
    final Dialog alert = new Dialog(this);
    alert.setTitle("Update history");
    alert.setContentView(R.layout.history_dialog);

    final Spinner checked = (Spinner) alert.findViewById(R.id.accountList);
    List<String> list = new ArrayList<String>();
    for (Account acc : portfolio.getAccounts()) {
        list.add(acc.getName());//from  w w w.j a v a 2 s .  c  om
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    checked.setAdapter(dataAdapter);

    Button dialogButton = (Button) alert.findViewById(R.id.dialogButtonOK);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshItem.setActionView(R.layout.progressbar);
            refreshItem.expandActionView();
            Account account = portfolio.getAccounts().get(checked.getSelectedItemPosition());
            EditText liquidityView = (EditText) alert.findViewById(R.id.liquidityMov);
            EditText yieldView = (EditText) alert.findViewById(R.id.yield);
            EditText buyView = (EditText) alert.findViewById(R.id.buy);
            EditText sellView = (EditText) alert.findViewById(R.id.sell);
            EditText taxeView = (EditText) alert.findViewById(R.id.taxe);
            EditText commentaryView = (EditText) alert.findViewById(R.id.commentaryEditText);

            String params = null;
            params = "?accountId=" + account.getId() + "&liquidity=" + liquidityView.getText() + "&yield="
                    + yieldView.getText() + "&buy=" + buyView.getText() + "&sell=" + sellView.getText()
                    + "&taxe=" + taxeView.getText() + "&commentary="
                    + commentaryView.getText().toString().replaceAll(" ", "%20");
            MainTask mainTask = new MainTask(OverallActivity.this, UrlType.UPDATEHISTORY, params);
            mainTask.execute((Void) null);
            alert.dismiss();
        }
    });
    dialogButton = (Button) alert.findViewById(R.id.dialogButtonCancel);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            alert.dismiss();
        }
    });
    alert.show();
}

From source file:com.facebook.android.FieldsConnectionsDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fields_connections_list);
    LayoutParams params = getWindow().getAttributes();
    params.width = LayoutParams.FILL_PARENT;
    params.height = LayoutParams.FILL_PARENT;
    getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

    fieldsList = (ListView) findViewById(R.id.fields_list);
    connectionsList = (ListView) findViewById(R.id.connections_list);

    fieldsAdapter = new FieldsListAdapter();
    if (this.fieldsArray == null) {
        fieldsList.setAdapter(new ArrayAdapter<String>(explorerActivity, android.R.layout.simple_list_item_1,
                new String[] { "No fields available" }));
    } else {/*  ww w  .ja  v  a  2 s.co  m*/
        fieldsList.setAdapter(fieldsAdapter);
    }

    connectionsAdapter = new ConnectionsListAdapter();
    if (this.connectionsArray == null) {
        connectionsList.setAdapter(new ArrayAdapter<String>(explorerActivity,
                android.R.layout.simple_list_item_1, new String[] { "No connections available" }));
    } else {
        connectionsList.setAdapter(connectionsAdapter);
    }

    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();

    TabSpec spec1 = tabHost.newTabSpec("Tab 1");
    spec1.setIndicator(explorerActivity.getString(R.string.fields));
    spec1.setContent(R.id.fields_layout);

    TabSpec spec2 = tabHost.newTabSpec("Tab 2");
    spec2.setIndicator(explorerActivity.getString(R.string.connections));
    spec2.setContent(R.id.connections_list);

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.setCurrentTab(0);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = TAB_HEIGHT;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = TAB_HEIGHT;

    mGetFieldsButton = (Button) findViewById(R.id.get_fields_button);
    mGetFieldsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*
             * Source Tag:
             */
            FieldsConnectionsDialog.this.dismiss();
            if (!fieldsVector.isEmpty()) {
                explorerActivity.getFields(fieldsVector);
            } else {
                Toast.makeText(explorerActivity.getBaseContext(), "No Fields selected.", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    connectionsList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            FieldsConnectionsDialog.this.dismiss();
            explorerActivity.getConnection(connectionsArray.get(position));
        }
    });
}

From source file:com.makerfaireorlando.app.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Assume true if the key does not yet exist
    prefs = getSharedPreferences("com.makerfaireorlando.app", MODE_PRIVATE);
    mCategories = new ArrayList<String>();

    if (savedInstanceState != null) {
        // Restore last state for checked position.
        mCurCheckPosition = savedInstanceState.getString("curChoice");
    } else {//from  w  ww .j  a va2 s  . co m
        try {
            getItemList();
        } catch (JSONException e) {
            Log.wtf("Main Activity", "Failed to get Item List");
        }
    }

    setContentView(R.layout.activity_main);

    //getSupportActionBar().setLogo(R.drawable.ic_actionbar);
    mTitle = mDrawerTitle = getTitle();
    titles = getResources().getStringArray(R.array.selection_array);

    classes = getResources().getStringArray(R.array.nav_classes);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, titles));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action ClickListenerto toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
            //getSupportFragmentManager().findFragmentByTag(mCurCheckPosition).setMenuVisibility(true);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
            //getSupportFragmentManager().findFragmentByTag(mCurCheckPosition).setMenuVisibility(false);

        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        FragmentTransaction tx = getSupportFragmentManager().beginTransaction().addToBackStack(null);
        tx.replace(R.id.content_frame, Fragment.instantiate(MainActivity.this, classes[0]), classes[0]);
        tx.commit();
        mCurCheckPosition = classes[0];
        mDrawerList.setItemChecked(0, true);
    }

}

From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java

@SuppressLint("InflateParams")
@Override//from  w w  w . j  a v  a  2  s  .  co  m
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object item = l.getItemAtPosition(position);
    final int changeId;
    if (item instanceof AutohideRule) {
        changeId = position - 1;
    } else {
        changeId = -1; //-1 - ?  
    }

    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
            ? new ContextThemeWrapper(this, R.style.Neutron_Medium)
            : this;
    View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null);
    final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex);
    final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner);
    final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname);
    final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum);
    final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment);
    final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject);
    final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name);

    chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans));
    if (changeId != -1) {
        AutohideRule rule = (AutohideRule) item;
        regexEditText.setText(rule.regex);
        int chanPosition = chans.indexOf(rule.chanName);
        chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0);
        boardEditText.setText(rule.boardName);
        threadEditText.setText(rule.threadNumber);
        inCommentCheckBox.setChecked(rule.inComment);
        inSubjectCheckBox.setChecked(rule.inSubject);
        inNameCheckBox.setChecked(rule.inName);
    } else {
        chanSpinner.setSelection(0);
    }

    DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String regex = regexEditText.getText().toString();
            if (regex.length() == 0) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            try {
                Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
            } catch (Exception e) {
                CharSequence message = null;
                if (e instanceof PatternSyntaxException) {
                    String eMessage = e.getMessage();
                    if (!TextUtils.isEmpty(eMessage)) {
                        SpannableStringBuilder a = new SpannableStringBuilder(
                                getString(R.string.autohide_error_incorrect_regex));
                        a.append('\n');
                        int startlen = a.length();
                        a.append(eMessage);
                        a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        message = a;
                    }
                }
                if (message == null)
                    message = getString(R.string.error_unknown);
                Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show();
                return;
            }

            AutohideRule rule = new AutohideRule();
            int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition();
            rule.regex = regex;
            rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? 
            rule.boardName = boardEditText.getText().toString();
            rule.threadNumber = threadEditText.getText().toString();
            rule.inComment = inCommentCheckBox.isChecked();
            rule.inSubject = inSubjectCheckBox.isChecked();
            rule.inName = inNameCheckBox.isChecked();

            if (!rule.inComment && !rule.inSubject && !rule.inName) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            if (changeId == -1) {
                rulesJson.put(rule.toJson());
            } else {
                rulesJson.put(changeId, rule.toJson());
            }
            rulesChanged();
        }
    };
    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView)
            .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title)
            .setPositiveButton(R.string.autohide_save_button, save)
            .setNegativeButton(android.R.string.cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:org.thomasamsler.android.flashcards.fragment.CardSetsFragment.java

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

    mActivity = (MainActivity) getActivity();
    mDataSource = mActivity.getDataSource();
    mMainApplication = (MainApplication) mActivity.getApplication();

    mMainApplication.registerAction(this, ACTION_DELETE_CARD_UPDATE_CARD_SET);

    registerForContextMenu(getListView());

    mProgressBar = (ProgressBar) mActivity.findViewById(R.id.progressBar);

    if (null == mCardSets) {

        mCardSets = mDataSource.getCardSets();
    }/*from ww w.j  a v  a2 s  .  c o  m*/

    if (0 == mCardSets.size()) {

        SharedPreferences sharedPreferences = mActivity.getSharedPreferences(AppConstants.PREFERENCE_NAME,
                Context.MODE_PRIVATE);
        boolean showSample = sharedPreferences.getBoolean(AppConstants.PREFERENCE_SHOW_SAMPLE,
                AppConstants.PREFERENCE_SHOW_SAMPLE_DEFAULT);

        if (showSample) {

            createDefaultCardSets();
            mCardSets = mDataSource.getCardSets();
        } else {

            Toast.makeText(mMainApplication, R.string.list_no_card_sets_message, Toast.LENGTH_SHORT).show();
        }
    }

    Collections.sort(mCardSets);

    mArrayAdapter = new ArrayAdapter<CardSet>(mActivity, android.R.layout.simple_list_item_1, mCardSets) {

        /*
         * Overwriting getView method to style the list item font. If it's a remote item
         * that hasn't been clicked on, we style it bold
         */
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            TextView textView = (TextView) super.getView(position, convertView, parent);
            CardSet cardSet = mCardSets.get(position);

            switch (cardSet.getCardCount()) {

            case 0:
                textView.setText(Html.fromHtml(
                        cardSet.getTitle() + "<br /><small><i><font color='#989898'>empty</font></i></small>"));
                break;
            case 1:
                textView.setText(Html.fromHtml(cardSet.getTitle() + "<br /><small><i><font color='#989898'>"
                        + cardSet.getCardCount() + " card</font></i></small>"));
                break;
            default:
                textView.setText(Html.fromHtml(cardSet.getTitle() + "<br /><small><i><font color='#989898'>"
                        + cardSet.getCardCount() + " cards</font></i></small>"));
                break;
            }

            if (mCardSets.get(position).isRemote()) {

                ((TextView) textView).setTypeface(Typeface.DEFAULT_BOLD);
            } else {

                ((TextView) textView).setTypeface(Typeface.DEFAULT);
            }

            return textView;
        }
    };

    setListAdapter(mArrayAdapter);

}

From source file:com.zion.htf.ui.DonateActivity.java

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

    this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    this.seekBar = (SeekBar) this.findViewById(R.id.seekBar);
    this.seekBar.setOnSeekBarChangeListener(this);
    this.seekBar.setMax(DonateActivity.SEEKBAR_MAX);

    this.amountEditText = (EditText) this.findViewById(R.id.amount);
    this.amountEditText.addTextChangedListener(this);

    Intent intent = new Intent(this, PayPalService.class);

    intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, DonateActivity.PAYPAL_ENVIRONMENT);
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, DonateActivity.PAYPAL_CLIENT_ID);

    this.startService(intent);

    // Initializes the amountEditText to reflects the internal value of amount
    this.amount = this.seekBar.getProgress() + DonateActivity.SEEKBAR_MIN;
    this.updateControls();

    if (null == DonateActivity.currencySet) {
        DonateActivity.currencySet = new DonateActivity.CurrencySet();
        DonateActivity.currencySet.add(new DonateActivity.Currency("US", "USD", "$"));
        DonateActivity.currencySet.add(new DonateActivity.Currency("CA", "CAD", "$CA"));
        DonateActivity.currencySet.add(new DonateActivity.Currency("GB", "GBP", ""));
        DonateActivity.currencySet.add(new DonateActivity.Currency("EU", "EUR", ""), true);
    }//from w ww  . j  a v  a  2s .  c  o  m

    this.currencySpinner = (Spinner) this.findViewById(R.id.currencySpinner);
    this.currencySpinner.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_dropdown_item, DonateActivity.currencySet.getLabelArray()));
    this.currencySpinner.setSelection(
            DonateActivity.currencySet.findPositionByCountryCode(Locale.getDefault().getCountry()));
}

From source file:org.starfishrespect.myconsumption.android.ui.AddSensorActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_sensor);

    Toolbar toolbar = getActionBarToolbar();
    getSupportActionBar().setTitle(getString(R.string.title_add_sensor));
    toolbar.setNavigationIcon(R.drawable.ic_up);

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//from  w w  w. j ava2 s  .  co  m
        public void onClick(View view) {
            Intent intent = getParentActivityIntent();
            startActivity(intent);
            finish();
        }
    });

    spinnerSensorType = (Spinner) findViewById(R.id.spinnerSensorType);
    editTextSensorName = (EditText) findViewById(R.id.editTextSensorName);
    layoutSensorSpecificSettings = (LinearLayout) findViewById(R.id.layoutSensorSpecificSettings);

    buttonCreateSensor = (Button) findViewById(R.id.buttonCreateSensor);

    if (getIntent().getExtras() != null) {
        Bundle b = getIntent().getExtras();
        if (b.containsKey("edit")) {
            try {
                editSensor = SingleInstance.getDatabaseHelper().getSensorDao().queryForId(b.getString("edit"));
                edit = true;
                editTextSensorName.setText(editSensor.getName());
                sensorTypes = new String[1];
                sensorTypes[0] = editSensor.getType();
                layoutSensorSpecificSettings.removeAllViews();
                selectedSensorType = sensorTypes[0].toLowerCase();
                sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType);
                sensorView.setEditMode(true);
                layoutSensorSpecificSettings.addView(sensorView);
                buttonCreateSensor.setText(R.string.button_edit_sensor);
            } catch (SQLException e) {
                finish();
            }
        }
    }

    spinnerSensorType.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensorTypes));

    if (!edit) {
        spinnerSensorType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                layoutSensorSpecificSettings.removeAllViews();
                selectedSensorType = sensorTypes[position].toLowerCase();
                sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType);
                layoutSensorSpecificSettings.addView(sensorView);
            }

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

            }
        });

        buttonCreateSensor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!MiscFunctions.isOnline(AddSensorActivity.this)) {
                    MiscFunctions.makeOfflineDialog(AddSensorActivity.this).show();
                    return;
                }
                if (editTextSensorName.getText().toString().equals("") || !sensorView.areSettingsValid()) {
                    new AlertDialog.Builder(AddSensorActivity.this).setTitle(R.string.dialog_title_error)
                            .setMessage("You must fill all the fields in order to add a sensor !")
                            .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).show();
                    return;
                }

                new AsyncTask<Void, Boolean, Void>() {
                    private ProgressDialog waitingDialog;

                    @Override
                    protected void onPreExecute() {
                        waitingDialog = new ProgressDialog(AddSensorActivity.this);
                        waitingDialog.setTitle(R.string.dialog_title_loading);
                        waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        waitingDialog.setMessage(
                                getResources().getString(R.string.dialog_message_loading_creating_sensor));
                        waitingDialog.show();
                    }

                    @Override
                    protected Void doInBackground(Void... params) {
                        publishProgress(create());
                        return null;
                    }

                    @Override
                    protected void onProgressUpdate(Boolean... values) {
                        for (boolean b : values) {
                            if (b) {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_information)
                                        .setMessage(R.string.dialog_message_information_sensor_added)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        setResult(RESULT_OK);
                                                        Intent intent = new Intent(AddSensorActivity.this,
                                                                ChartActivity.class);
                                                        intent.putExtra(Config.EXTRA_FIRST_LAUNCH, true);
                                                        startActivity(intent);
                                                    }
                                                })
                                        .show();
                            } else {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_error)
                                        .setMessage(R.string.dialog_message_error_sensor_not_added)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                    }
                                                })
                                        .show();
                            }
                        }
                    }

                    @Override
                    protected void onPostExecute(Void aVoid) {
                        waitingDialog.dismiss();
                    }
                }.execute();
            }
        });
    } else {
        buttonCreateSensor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AsyncTask<Void, Boolean, Void>() {
                    private ProgressDialog waitingDialog;

                    @Override
                    protected void onPreExecute() {
                        waitingDialog = new ProgressDialog(AddSensorActivity.this);
                        waitingDialog.setTitle(R.string.dialog_title_loading);
                        waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        waitingDialog.setMessage(
                                getResources().getString(R.string.dialog_message_loading_editing_sensor));
                        waitingDialog.show();
                    }

                    @Override
                    protected Void doInBackground(Void... params) {
                        publishProgress(edit());
                        return null;
                    }

                    @Override
                    protected void onProgressUpdate(Boolean... values) {
                        for (boolean b : values) {
                            if (b) {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_information)
                                        .setMessage(R.string.dialog_message_information_sensor_edited)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        setResult(Activity.RESULT_OK);
                                                        finish();
                                                    }
                                                })
                                        .show();
                            } else {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_error)
                                        .setMessage(R.string.dialog_message_error_sensor_not_added)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                    }
                                                })
                                        .show();
                            }
                        }
                    }

                    @Override
                    protected void onPostExecute(Void aVoid) {
                        waitingDialog.dismiss();
                    }
                }.execute();
            }
        });

    }
}

From source file:com.deliciousdroid.fragment.AddBookmarkFragment.java

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

    base = (FragmentBaseActivity) getActivity();

    setHasOptionsMenu(true);/*from   www .j a  v  a2  s  . c  om*/

    mEditUrl = (EditText) getView().findViewById(R.id.add_edit_url);
    mEditDescription = (EditText) getView().findViewById(R.id.add_edit_description);
    mDescriptionProgress = (ProgressBar) getView().findViewById(R.id.add_description_progress);
    mEditNotes = (EditText) getView().findViewById(R.id.add_edit_notes);
    mEditTags = (MultiAutoCompleteTextView) getView().findViewById(R.id.add_edit_tags);
    mRecommendedTags = (TextView) getView().findViewById(R.id.add_recommended_tags);
    mRecommendedProgress = (ProgressBar) getView().findViewById(R.id.add_recommended_tags_progress);
    mPopularTags = (TextView) getView().findViewById(R.id.add_popular_tags);
    mPopularProgress = (ProgressBar) getView().findViewById(R.id.add_popular_tags_progress);
    mPrivate = (CompoundButton) getView().findViewById(R.id.add_edit_private);

    mRecommendedTags.setMovementMethod(LinkMovementMethod.getInstance());
    mPopularTags.setMovementMethod(LinkMovementMethod.getInstance());

    if (base.mAccount != null) {
        String[] tagArray = new String[5];
        tagArray = TagManager.GetTagsAsArray(base.mAccount.name, Tag.Name + " ASC", base).toArray(tagArray);
        ArrayAdapter<String> autoCompleteAdapter = new ArrayAdapter<String>(base, R.layout.autocomplete_view,
                tagArray);
        mEditTags.setAdapter(autoCompleteAdapter);
        mEditTags.setTokenizer(new SpaceTokenizer());
    }

    mEditUrl.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                String url = mEditUrl.getText().toString();

                if (mEditDescription.getText().toString().equals("")) {
                    titleTask = new GetTitleTask().execute(url);
                }
                tagTask = new GetTagSuggestionsTask().execute(url);
            }
        }
    });
}

From source file:fm.smart.r1.activity.CreateItemActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExceptionHandler.register(this);
    setContentView(R.layout.create_item);
    final Intent queryIntent = getIntent();
    Bundle extras = queryIntent.getExtras();
    list_id = (String) extras.get("list_id");
    cue = (String) extras.get("cue");
    response = (String) extras.get("response");
    cue_language = (String) extras.get("cue_language");
    response_language = (String) extras.get("response_language");
    character_cue = (String) extras.get("character_cue");
    character_response = (String) extras.get("character_response");
    pos = (String) extras.get("pos");

    Button button = (Button) findViewById(R.id.create_item_submit);
    button.setOnClickListener(this);

    TextView cue_text = (TextView) findViewById(R.id.cue);
    if (!TextUtils.isEmpty(cue)) {
        cue_text.setText(cue);/* www  . j av a 2  s  . c  om*/
    }
    TextView response_text = (TextView) findViewById(R.id.response);
    if (!TextUtils.isEmpty(response)) {
        response_text.setText(response);
    }
    TextView cue_character_text = (TextView) findViewById(R.id.cue_character);
    if (!TextUtils.isEmpty(character_cue)) {
        cue_character_text.setText(character_cue);
    }
    TextView response_character_text = (TextView) findViewById(R.id.response_character);
    if (!TextUtils.isEmpty(character_response)) {
        response_character_text.setText(character_response);
    }

    TextView cue_legend = (TextView) findViewById(R.id.create_item_cue_legend);
    cue_legend.setText(Utils.INV_LANGUAGE_MAP.get(cue_language) + " Term");
    TextView response_legend = (TextView) findViewById(R.id.create_item_response_legend);
    response_legend.setText(Utils.INV_LANGUAGE_MAP.get(response_language) + " Term");
    TextView cue_character_textView = (TextView) findViewById(R.id.create_item_cue_character);
    cue_character_textView.setText(Utils.INV_LANGUAGE_MAP.get(cue_language) + " Character Text");
    TextView response_character_textView = (TextView) findViewById(R.id.create_item_response_character);
    response_character_textView.setText(Utils.INV_LANGUAGE_MAP.get(response_language) + " Character Text");

    List<String> pos_list = new Vector<String>(Utils.POS_MAP.keySet());
    Collections.sort(pos_list);

    ArrayAdapter<String> pos_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            pos_list);
    // .simple_spinner_item
    Spinner pos_textView = (Spinner) findViewById(R.id.pos);
    pos_textView.setAdapter(pos_adapter);
    if (!TextUtils.isEmpty(pos)) {
        pos_textView.setSelection(pos_list.indexOf(pos));
    } else {
        pos_textView.setSelection(pos_list.indexOf("Noun"));
    }

    EditText cue_character_input_textView = (EditText) findViewById(R.id.cue_character);
    if (!Utils.isIdeographicLanguage(Main.search_lang)) {
        cue_character_textView.setVisibility(View.GONE);
        cue_character_input_textView.setVisibility(View.GONE);
    } else if (!TextUtils.isEmpty(character_cue)) {
        cue_character_input_textView.setText(character_cue);
    }

    EditText response_character_input_textView = (EditText) findViewById(R.id.response_character);
    if (!Utils.isIdeographicLanguage(Main.result_lang)) {
        response_character_textView.setVisibility(View.GONE);
        response_character_input_textView.setVisibility(View.GONE);
    } else if (!TextUtils.isEmpty(character_response)) {
        response_character_input_textView.setText(character_response);
    }

}