Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

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

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:de.hshannover.f4.trust.ironcontrol.view.list_activities.ListVendorMetadataActivity.java

private Dialog addMetaAttribute() {
    AlertDialog.Builder publishSaveDialog = createDialog(R.string.add);

    final EditText input = new EditText(this);
    publishSaveDialog.setView(input);// w  ww.j a v  a  2 s . c om

    publishSaveDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            Editable value = input.getText();

            String name = value.toString();
            ContentValues publishValues = new ContentValues();
            publishValues.put(MetaAttributes.COLUMN_NAME, name);
            getContentResolver().insert(Uri.parse(DBContentProvider.VENDOR_METADATA_URI + "/" + lastMetadataID
                    + "/" + DBContentProvider.VENDOR_META_ATTRIBUTES), publishValues);
        }
    });

    publishSaveDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });

    return publishSaveDialog.create();
}

From source file:me.ziccard.secureit.MonitorActivity.java

/**
 * Shows a dialog prompting the unlock code
 */// w w  w. jav  a  2 s  . c  om
private void createUnlockDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Stop monitoring?");
    final EditText input = new EditText(this);
    input.setHint("Unlock code");
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    builder.setView(input);

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            if (input.getText().toString().equals(preferences.getUnlockCode())) {
                Log.i("MonitorActivity", "INPUT " + input.getText().toString());
                Log.i("MonitorActivity", "STORED " + preferences.getUnlockCode());
                dialog.dismiss();
                close();
            } else {
                dialog.dismiss();
                Toast.makeText(getApplicationContext(), "Wrong unlock code", Toast.LENGTH_SHORT).show();
            }
        }
    });

    builder.show();
}

From source file:com.softminds.matrixcalculator.base_activities.FillingMatrix.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false);
    boolean SmartFit = preferences.getBoolean("SMART_FIT_KEY", false);

    if (isDark)/* w  w w.j  a v  a 2s .  c  om*/
        setTheme(R.style.AppThemeDark_NoActionBar);
    else
        setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);

    Bundle bundle = getIntent().getExtras();
    if (bundle == null) {
        Log.wtf("FillingMatrix", "How the heck, it got called ??");
        Toast.makeText(getApplication(), R.string.unexpected_error, Toast.LENGTH_SHORT).show();
        finish();
    } else {
        col = bundle.getInt("COL");
        row = bundle.getInt("ROW");
    }
    setContentView(R.layout.filler);
    adCard = findViewById(R.id.AddCardFiller);

    if (!((GlobalValues) getApplication()).DonationKeyFound()) {
        AdView adView = findViewById(R.id.adViewFiller);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.setAdListener(new AdLoadListener(adCard));
        adView.loadAd(adRequest);
        if (getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE)
            adCard.setVisibility(View.INVISIBLE);
        else
            adCard.setVisibility(View.VISIBLE);
    } else
        ((ViewGroup) adCard.getParent()).removeView(adCard);

    Toolbar toolbar = findViewById(R.id.toolbarFill);
    setSupportActionBar(toolbar);

    CardView cardView = findViewById(R.id.DynamicCard);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
    String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");

    cardView.setCardElevation(Integer.parseInt(string));

    CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    GridLayout gridLayout = new GridLayout(getApplicationContext());
    gridLayout.setRowCount(row);
    gridLayout.setColumnCount(col);
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            EditText editText = new EditText(getApplication());
            editText.setBackgroundColor(Color.parseColor(string2));
            editText.setId(i * 10 + j);
            if (isDark)
                editText.setTextColor(ContextCompat.getColor(this, R.color.white));
            editText.setGravity(Gravity.CENTER);
            SpannableStringBuilder stringBuilder = new SpannableStringBuilder(
                    "a" + String.valueOf(i + 1) + String.valueOf(j + 1));
            stringBuilder.setSpan(new SubscriptSpan(), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            stringBuilder.setSpan(new RelativeSizeSpan(0.75f), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            editText.setHint(stringBuilder);
            if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("DECIMAL_USE", true)) {
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
            } else {
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                        | InputType.TYPE_NUMBER_FLAG_SIGNED);
            }
            editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(getLength()) });
            if (SmartFit) {
                editText.setWidth(ConvertTopx(CalculatedWidth(col)));
                editText.setTextSize(SizeReturner(row, col,
                        PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                                .getBoolean("EXTRA_SMALL_FONT", false)));
            } else {
                editText.setWidth(ConvertTopx(62));
                editText.setTextSize(SizeReturner(3, 3,
                        PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                                .getBoolean("EXTRA_SMALL_FONT", false)));
            }
            editText.setSingleLine();
            GridLayout.Spec Row = GridLayout.spec(i, 1);
            GridLayout.Spec Col = GridLayout.spec(j, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
            params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = getResources()
                    .getDimensionPixelOffset(R.dimen.border_width);
            gridLayout.addView(editText, params);
        }
    }
    gridLayout.setLayoutParams(params1);
    cardView.addView(gridLayout);
    MakeType((Type) (getIntent().getExtras().getSerializable("TYPE")));
    if (GetMaximum() < GetMinimum()) {
        final Snackbar snackbar;
        snackbar = Snackbar.make(findViewById(R.id.filling_matrix), R.string.Warning3,
                Snackbar.LENGTH_INDEFINITE);
        snackbar.show();
        snackbar.setAction(getString(R.string.action_settings), new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                snackbar.dismiss();
                Intent intent = new Intent(getApplicationContext(), SettingsTab.class);
                startActivity(intent);
                finish();
            }
        });
    }

}

From source file:org.cafemember.messenger.mytg.fragments.TransfareActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    context = getContext();//w ww .  ja  va2 s.c  om
    //        View layout = inflater.inflate(R.layout.channels_layout, null);
    /*this.context = context;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("MenuTransfare", R.string.MenuTransfare));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
    @Override
    public void onItemClick(int id) {
        if (id == -1) {
            finishFragment();
        } else if (id == done_button) {
            saveName();
        }else if (id == contact_button) {
            getContacts();
        }
    }
    });
            
    ActionBarMenu menu = actionBar.createMenu();
    contactsButton = menu.addItemWithWidth(contact_button, R.drawable.user_profile, AndroidUtilities.dp(56));
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    */

    LinearLayout fragmentView = new LinearLayout(context);
    ((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    TextView ruleTextView = new TextView(context);
    ruleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    ruleTextView.setTextColor(0xff212121);
    ruleTextView.setGravity(Gravity.RIGHT);
    //        ruleTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("ShareText", R.string.ShareText)));
    ruleTextView.setText(LocaleController.getString("transfare_rule", R.string.transfare_rule));
    ((LinearLayout) fragmentView).addView(ruleTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 24, 10, 24, 30));

    phoneField = new EditText(context);
    phoneField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    phoneField.setHintTextColor(0xff979797);
    phoneField.setTextColor(0xff212121);
    phoneField.setMaxLines(1);
    phoneField.setLines(1);
    phoneField.setGravity(Gravity.RIGHT);
    phoneField.setPadding(0, 0, 0, 0);
    phoneField.setSingleLine(true);
    phoneField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    phoneField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    phoneField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    phoneField.setHint(LocaleController.getString("TransfareUserHint", R.string.TransfareUserHint));
    AndroidUtilities.clearCursorDrawable(phoneField);

    amountField = new EditText(context);
    amountField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    amountField.setHintTextColor(0xff979797);
    amountField.setTextColor(0xff212121);
    amountField.setMaxLines(1);
    amountField.setGravity(Gravity.RIGHT);
    amountField.setLines(1);
    amountField.setPadding(0, 0, 0, 0);
    amountField.setSingleLine(true);
    amountField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    amountField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    amountField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    amountField.setHint(LocaleController.getString("TransfareAmountHint", R.string.TransfareAmountHint));
    AndroidUtilities.clearCursorDrawable(amountField);

    phoneField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                doneButton.performClick();
                return true;
            }
            return false;
        }
    });

    ((LinearLayout) fragmentView).addView(phoneField,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));

    checkTextView = new TextView(context);
    checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    checkTextView.setGravity(Gravity.RIGHT);
    ((LinearLayout) fragmentView).addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 12, 24, 0));

    Button button = new Button(context);

    button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    button.setTextColor(0xff6d6d72);
    button.setGravity(Gravity.CENTER);
    TextView helpTextView = new TextView(context);
    helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    helpTextView.setTextColor(0xff6d6d72);
    helpTextView.setGravity(Gravity.RIGHT);
    helpTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("RefHelp", R.string.RefHelp)));
    button.setText("");
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveName();
        }
    });
    ((LinearLayout) fragmentView).addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 0));
    ((LinearLayout) fragmentView).addView(amountField,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
    ((LinearLayout) fragmentView).addView(button,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 24, 24, 0));

    /*View v = LayoutInflater.from(context).inflate(R.layout.transfare_type, null);
    typeJoin = (RadioButton)v.findViewById(R.id.joinRadio);
    typeView = (RadioButton)v.findViewById(R.id.viewRadio);
    ((LinearLayout) fragmentView).addView(v, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));*/
    phoneField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            checkUserName(phoneField.getText().toString(), false);
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    checkTextView.setVisibility(View.GONE);
    FontManager.instance().setTypefaceImmediate(fragmentView);

    return fragmentView;
}

From source file:com.morlunk.mumbleclient.channel.UserMenu.java

@Override
public boolean onMenuItemClick(final MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.context_ban:
    case R.id.context_kick:
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
        alertBuilder.setTitle(R.string.user_menu_kick);
        final EditText reasonField = new EditText(mContext);
        reasonField.setHint(R.string.hint_reason);
        alertBuilder.setView(reasonField);
        alertBuilder.setPositiveButton(R.string.user_menu_kick, new DialogInterface.OnClickListener() {
            @Override//from  w  w  w.  ja v  a 2s . com
            public void onClick(DialogInterface dialog, int which) {
                mService.kickBanUser(mUser.getSession(), reasonField.getText().toString(),
                        menuItem.getItemId() == R.id.context_ban);
            }
        });
        alertBuilder.setNegativeButton(android.R.string.cancel, null);
        alertBuilder.show();
        break;
    case R.id.context_mute:
        mService.setMuteDeafState(mUser.getSession(), !(mUser.isMuted() || mUser.isSuppressed()),
                mUser.isDeafened());
        break;
    case R.id.context_deafen:
        mService.setMuteDeafState(mUser.getSession(), mUser.isMuted(), !mUser.isDeafened());
        break;
    case R.id.context_move:
        showChannelMoveDialog();
        break;
    case R.id.context_priority:
        mService.setPrioritySpeaker(mUser.getSession(), !mUser.isPrioritySpeaker());
        break;
    case R.id.context_local_mute:
        mUser.setLocalMuted(!mUser.isLocalMuted());
        mStateListener.onLocalUserStateUpdated(mUser);
        break;
    case R.id.context_ignore_messages:
        mUser.setLocalIgnored(!mUser.isLocalIgnored());
        mStateListener.onLocalUserStateUpdated(mUser);
        break;
    case R.id.context_change_comment:
        showUserComment(true);
        break;
    case R.id.context_view_comment:
        showUserComment(false);
        break;
    case R.id.context_reset_comment:
        new AlertDialog.Builder(mContext)
                .setMessage(mContext.getString(R.string.confirm_reset_comment, mUser.getName()))
                .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mService.setUserComment(mUser.getSession(), "");
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
        break;
    //                case R.id.context_info:
    //                    break;
    case R.id.context_register:
        mService.registerUser(mUser.getSession());
        break;
    default:
        return false;
    }
    return true;
}

From source file:com.marvin.rocklock.PlaylistUtils.java

/**
 * Adds a given song to an existing playlist
 *
 * @param context the managing activity//  w  w  w.j a va2s. co  m
 * @param id the song id to add
 */
public static void showPlaylistDialog(final RockLockActivity context, final String id) {

    // Get list of playlists
    String[] proj = { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME };
    CursorLoader loader = new CursorLoader(context, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, proj, null,
            null, null);
    final Cursor playlistCursor = loader.loadInBackground();
    // Show playlists
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (playlistCursor.moveToFirst()) {
        DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                addToPlaylist(context, playlistCursor.getInt(0), id);
            }

        };
        builder.setCursor(playlistCursor, clickListener, MediaStore.Audio.Playlists.NAME);
    } else {
        // No playlists: show create dialog
        builder.setTitle(context.getString(R.string.new_playlist));
        // TODO(sainsley): add default name based on
        // number of playlists in directory
        builder.setMessage(context.getString(R.string.enter_playlist_name));

        final EditText input = new EditText(context);
        builder.setView(input);

        builder.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                String name = input.getText().toString();
                ArrayList<String> ids = new ArrayList<String>();
                ids.add(id);
                writePlaylist(context, name, ids);
                return;
            }
        });
    }
    builder.show();
}

From source file:adventure_fragments.Hiking.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);/* w ww  .  ja  va 2  s.c o m*/
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemHiking(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsHiking();
                adapt = new CustomAdapter2(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_hike);
                listItem.setAdapter(adapt);

                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Running.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);/*w ww . ja va  2 s  .  c o  m*/
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemRunning(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsRunning();
                adapt = new CustomAdapter4(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_run);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Skiing.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);//  ww w  .ja  va  2  s .  co  m
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemSkiing(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsSkiing();
                adapt = new CustomAdapter5(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_ski);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:com.tnc.android.graphite.activities.GraphActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO move to controller
    switch (item.getItemId()) {
    case R.id.graph_menu_reload:
        controller.handleMessage(GraphController.MESSAGE_RELOAD);
        break;//from   www .j  av  a  2  s .  c o  m
    case R.id.graph_menu_auto_refresh:
        controller.handleMessage(GraphController.MESSAGE_AUTO_REFRESH_DIALOG);
        break;
    case R.id.graph_menu_edit:
        layout.closeDrawers();
        Intent editIntent = new Intent(this, EditActivity.class);
        startActivityForResult(editIntent, GraphController.ACTIVITY_EDIT_GRAPHS);
        break;
    case R.id.graph_menu_save:
        final EditText input = new EditText(this);
        final AlertDialog saveDialog = new AlertDialog.Builder(this).setTitle(R.string.save_dialog_title)
                .setView(input).setPositiveButton(R.string.dialog_positive, null)
                .setNegativeButton(R.string.dialog_negative, null).create();
        saveDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button b = saveDialog.getButton(AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String value = input.getText().toString();
                        if (!value.equals("")) {
                            controller.handleMessage(GraphController.MESSAGE_SAVE_GRAPH, value);
                            saveDialog.dismiss();
                        }
                    }
                });
            }
        });
        saveDialog.show();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}