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:com.terracom.mumbleclient.servers.PublicServerListFragment.java

@Override
public void favouriteServer(final Server server) {
    final Settings settings = Settings.getInstance(getActivity());
    final EditText usernameField = new EditText(getActivity());
    usernameField.setHint(settings.getDefaultUsername());
    AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
    adb.setTitle(R.string.addFavorite);//w  w  w  . j  av a  2  s .c  o  m
    adb.setView(usernameField);
    adb.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (usernameField.getText().length() > 0) {
                server.setUsername(usernameField.getText().toString());
            } else {
                server.setUsername(settings.getDefaultUsername());
            }
            QRPushToTalkDatabase database = mDatabaseProvider.getDatabase();
            database.addServer(server);
        }
    });
    adb.setNegativeButton(android.R.string.cancel, null);
    adb.show();
}

From source file:com.secbro.qark.exportedcomponent.exportedactivity.IntentParamsFragment.java

private void createKeyValuePairLayout(String key, LinearLayout topLayout) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    TextView keyTextView = new TextView(getActivity());
    keyTextView.setTag("key" + key);
    keyTextView.setText(key);/*from  w w  w  .  ja  va2 s .  co m*/
    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(50, 40, 50, 10); // llp.setMargins(left, top, right, bottom);
    keyTextView.setLayoutParams(llp);

    LinearLayout.LayoutParams llp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    EditText valueEditText = new EditText(getActivity());
    valueEditText.setTag("value" + key);
    valueEditText.setLayoutParams(llp1);

    linearLayout.addView(keyTextView);
    linearLayout.addView(valueEditText);
    topLayout.addView(linearLayout);
}

From source file:com.audiokernel.euphonyrmt.fragments.BrowseFragment.java

private void addToPlaylist(final MenuItem item) {
    final EditText input = new EditText(getActivity());
    final int id = item.getOrder();
    if (item.getItemId() == 0) {
        new AlertDialog.Builder(getActivity()).setTitle(R.string.playlistName)
                .setMessage(R.string.newPlaylistPrompt).setView(input)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override/*from w  ww .j  a  v  a 2 s . com*/
                    public void onClick(final DialogInterface dialog, final int which) {
                        final String name = input.getText().toString().trim();
                        if (!name.isEmpty()) {
                            mApp.oMPDAsyncHelper.execAsync(new Runnable() {
                                @Override
                                public void run() {
                                    add(mItems.get(id), name);
                                }
                            });
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        // Do nothing.
                    }
                }).show();
    } else {
        add(mItems.get(id), item.getTitle().toString());
    }
}

From source file:com.cairoconfessions.MainActivity.java

public void report(View view) {

    final EditText edit = new EditText(this);
    final RadioGroup choices = new RadioGroup(this);
    edit.setText("I would like to report this confession");
    final String[] selectedItem = getResources().getStringArray(R.array.report_choices);

    for (int i = 0; i < selectedItem.length; i++) {
        RadioButton choice = new RadioButton(this);
        choice.setText(selectedItem[i]);
        choices.addView(choice);//from www  .j  a  v a 2 s .c o  m
    }
    choices.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // checkedId is the RadioButton selected
            edit.setText("I would like to report this confession as "
                    + ((RadioButton) group.findViewById(checkedId)).getText().toString());

        }
    });
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(choices);
    ll.addView(edit);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Choose which categories:").setView(ll)
            .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked OK button
                    reportReceived();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked Cancel button
                }
            }).show();
}

From source file:org.telegram.ui.myLocationSettingsActivity.java

@Override
public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        actionBar.setAllowOverlayTitle(true);
        actionBar.setTitle("My Places");
        actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
            @Override//w  ww  .  j  a  va 2  s .  c  om
            public void onItemClick(int id) {
                if (id == -1) {
                    finishFragment();
                }
            }
        });

        listAdapter = new ListAdapter(getParentActivity());

        fragmentView = new FrameLayout(getParentActivity());
        FrameLayout frameLayout = (FrameLayout) fragmentView;
        frameLayout.setBackgroundColor(0xfff0f0f0);

        ListView listView = new ListView(getParentActivity());
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == homeRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Home");
                    final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(50, 30);
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    input.setLayoutParams(lparams);
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationHome = new getCoordinates().execute(city).get();
                                    String latHome = locationHome.getString("lat");
                                    String lonHome = locationHome.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latHome", latHome);
                                    editor.putString("longHome", lonHome);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + lonHome);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == workRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Work");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationWork = new getCoordinates().execute(city).get();
                                    String latWork = locationWork.getString("lat");
                                    String lonWork = locationWork.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latWork", latWork);
                                    editor.putString("longWork", lonWork);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latWork);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == entertainmentRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Entertainment");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationEntertainment = new getCoordinates().execute(city).get();
                                    String latEntertainment = locationEntertainment.getString("lat");
                                    String lonEntertainment = locationEntertainment.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latEntertainment", latEntertainment);
                                    editor.putString("longEntertainment", lonEntertainment);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latEntertainment);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                }
                //TODO find a solution for commuteRow as well!!
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.stan.createcustommap.MainActivity.java

private void addMarker() {
    if (mMap != null) {
        LinearLayout layout = new LinearLayout(MainActivity.this);
        layout.setLayoutParams(new ActionBar.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        layout.setOrientation(LinearLayout.VERTICAL);

        final EditText titleField = new EditText(MainActivity.this);
        titleField.setHint("Title");

        final EditText latField = new EditText(MainActivity.this);
        latField.setHint("Latitude");
        latField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);
        final EditText longField = new EditText(MainActivity.this);
        longField.setHint("Longitude");
        longField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);

        layout.addView(titleField);/*w  w w .  j av a2s  .  c om*/
        layout.addView(latField);
        layout.addView(longField);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Add Marker");
        builder.setView(layout);
        AlertDialog alertDialog = builder.create();
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean parsable = true;
                Double lat = null, lon = null;
                String strLat = latField.getText().toString();
                String strLon = longField.getText().toString();
                String strTitle = titleField.getText().toString();
                try {
                    lat = Double.parseDouble(strLat);

                } catch (NumberFormatException ex) {
                    parsable = false;
                    Toast.makeText(MainActivity.this, "Latitude does not contain a parsable double",
                            Toast.LENGTH_LONG).show();
                }
                try {
                    lon = Double.parseDouble(strLon);
                } catch (NumberFormatException ex) {
                    parsable = false;
                    Toast.makeText(MainActivity.this, "Longitude does not contain a parsable double",
                            Toast.LENGTH_LONG);
                }
                if (parsable) {
                    LatLng targetLatLng = new LatLng(lat, lon);
                    MarkerOptions markerOptions = new MarkerOptions().position(targetLatLng).title(strTitle);

                    markerOptions.draggable(true);
                    mMap.addMarker(markerOptions);
                    mMap.moveCamera(CameraUpdateFactory.newLatLng(targetLatLng));
                }

            }
        });
        builder.setNegativeButton("Cancel", null);
        builder.show();
    } else {
        Toast.makeText(MainActivity.this, "Map not ready", Toast.LENGTH_LONG).show();
    }
}

From source file:hcm.ssj.creator.dialogs.FileDialog.java

/**
 * @param savedInstanceState Bundle//from w  w w . j av a 2  s. com
 * @return Dialog
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(titleMessage);
    builder.setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            switch (type) {
            case SAVE: {
                String fileName = editText.getText().toString().trim();
                File dir1 = new File(Environment.getExternalStorageDirectory(), Util.DIR_1);
                File dir2 = new File(dir1.getPath(), Util.DIR_2);
                if (!fileName.isEmpty() && (dir2.exists() || dir2.mkdirs())) {
                    if (!fileName.endsWith(Util.SUFFIX)) {
                        fileName += Util.SUFFIX;
                    }
                    File file = new File(dir2, fileName);
                    if (isValidFileName(file) && SaveLoad.save(file)) {
                        for (Listener listener : alListeners) {
                            listener.onPositiveEvent(null);
                        }
                        return;
                    }
                }
                for (Listener listener : alListeners) {
                    listener.onNegativeEvent(new Boolean[] { false });
                }
                return;
            }
            case LOAD:
            case DELETE: {
                if (xmlFiles != null && xmlFiles.length > 0) {
                    int pos = listView.getCheckedItemPosition();
                    if (pos > AbsListView.INVALID_POSITION) {
                        if (type == Type.DELETE && xmlFiles[pos].delete()) {
                            for (Listener listener : alListeners) {
                                listener.onPositiveEvent(null);
                            }
                            return;
                        } else if (type == Type.LOAD) {
                            if (SaveLoad.load(xmlFiles[pos])) {
                                for (Listener listener : alListeners) {
                                    listener.onPositiveEvent(null);
                                }
                                return;
                            }
                        }
                        for (Listener listener : alListeners) {
                            listener.onNegativeEvent(new Boolean[] { false });
                        }
                        return;
                    }
                }
                for (Listener listener : alListeners) {
                    listener.onNegativeEvent(null);
                }
                break;
            }
            }
        }
    });
    builder.setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            for (Listener listener : alListeners) {
                listener.onNegativeEvent(null);
            }
        }
    });
    //set up the input
    switch (type) {
    case SAVE: {
        editText = new EditText(getContext());
        editText.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
        editText.setInputType(InputType.TYPE_CLASS_TEXT);
        builder.setView(editText);
        break;
    }
    case LOAD:
    case DELETE: {
        listView = new ListView(getContext());
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        File dir1 = new File(Environment.getExternalStorageDirectory(), Util.DIR_1);
        File dir2 = new File(dir1.getPath(), Util.DIR_2);
        xmlFiles = dir2.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File folder, String name) {
                return name.toLowerCase().endsWith(Util.SUFFIX);
            }
        });
        if (xmlFiles != null && xmlFiles.length > 0) {
            String[] ids = new String[xmlFiles.length];
            for (int i = 0; i < ids.length; i++) {
                ids[i] = xmlFiles[i].getName();
            }
            listView.setAdapter(
                    new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_single_choice, ids));
        } else {
            listView.setAdapter(
                    new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_single_choice));
        }
        builder.setView(listView);
        break;
    }
    }
    return builder.create();
}

From source file:de.trier.infsec.koch.droidsheep.activities.HijackActivity.java

private void selectURL() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(getString(R.string.changeurl));
    alert.setMessage(getString(R.string.customurl));

    // Set an EditText view to get user input   
    final EditText inputName = new EditText(this);
    inputName.setText(HijackActivity.this.webview.getUrl());
    alert.setView(inputName);/*from   ww w .ja  v  a 2 s.c  om*/

    alert.setPositiveButton("Go", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            HijackActivity.this.webview.loadUrl(inputName.getText().toString());
        }
    });

    alert.show();
}

From source file:com.launcher.silverfish.launcher.appdrawer.TabbedAppDrawerFragment.java

private void promptRenameTab(final TabInfo tab, final int tab_index) {

    // Find which tab we're renaming
    String tabName = tab.getLabel();

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(String.format(getString(R.string.text_renaming_tab), tabName));

    // Set up the input
    final EditText input = new EditText(getContext());
    // Specify the type of input expected
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);//from  www. ja  va 2 s  .c  om

    // Set up the buttons
    builder.setPositiveButton(getString(R.string.text_rename), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                tabHandler.renameTab(tab, tab_index, input.getText().toString());
            } catch (IllegalArgumentException e) {
                /* This means that the user entered an empty name */
                showToast(R.string.text_cannot_name_empty);
            }
        }
    });
    builder.setNegativeButton(getString(R.string.text_cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:com.bti360.hackathon.listview.HackathonActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case ADD_DIALOG:
        // We are going to create an AlertDialog with a single text input and a button
        // first we create the EditText
        final EditText edit = new EditText(this);
        // Next we create an AlertDialog.Builder which creates a styled AlertDialog based
        // on our specifications;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // set the title
        builder.setTitle("Add Person");
        // set the icon to a built-in, this one is a +
        builder.setIcon(android.R.drawable.ic_input_add);
        // set the text of the only button, and add a click listener
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            @Override/*from   ww  w .  j  a v  a2  s .  c  o m*/
            public void onClick(DialogInterface dialog, int which) {
                // on the Ok Button we grab the text from the EditText,
                // clear it and then add the Name to our list
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
            }
        });
        // finally let's create the dialog
        final AlertDialog d = builder.create();
        // and set the view to our EditText
        d.setView(edit);

        // we'll set a special InputType since we are collecting a name
        // other's exist such as email, address, phone number, etc
        // this allows the IME (keyboard) to customize itself based on
        // expected input, e.g. show @ and .com when Email
        edit.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        // Respond to the default action on the IME (keyboard) By default it is
        // "Done" but it can be changed with setImeActionLabel to be something
        // else like a search hourglass.
        // In our case we want a click on "Done" to do the same thing as a click
        // on the Ok button in the Dialog.
        edit.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView tv, int actionId, KeyEvent arg2) {
                // same as the DialogClick Handler except we also dismiss the dialog
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
                d.dismiss();
                return true;
            }
        });
        return d;
    }
    return super.onCreateDialog(id);
}