List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.example.team04adventure.Controller.OnlineStoryList.java
/** * Starts a dialog box which allows the user to create a new story. * // w w w. ja v a 2s.c om * @param view * the current view. */ public void addStory(View view) { AlertDialog.Builder adb = new AlertDialog.Builder(this); LinearLayout lila1 = new LinearLayout(this); lila1.setOrientation(1); final EditText titleinput = new EditText(this); final EditText bodyinput = new EditText(this); titleinput.setHint("Enter the Title here."); bodyinput.setHint("Enter a Synopsis here."); lila1.addView(titleinput); lila1.addView(bodyinput); adb.setView(lila1); adb.setTitle("New Story"); adb.setNegativeButton("Create", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Story story = new Story(); story.setTitle(titleinput.getText().toString()); Random rg = new Random(); int rint = rg.nextInt(100); story.setSynopsis(bodyinput.getText().toString()); story.setId(story.getTitle().replace(" ", "") + rint); story.setAuthor(MainActivity.username); story.setVersion(1); StorageManager sm = new StorageManager(getBaseContext()); sm.addStory(story); Intent intent = new Intent(OnlineStoryList.this, OnlineStoryList.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); adb.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); adb.show(); }
From source file:arc.noaa.weather.activities.MainActivity.java
private void searchCities() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(this.getString(R.string.search_title)); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setMaxLines(1);//from w w w . jav a 2 s.c o m input.setSingleLine(true); alert.setView(input, 32, 0, 32, 0); alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String result = input.getText().toString(); if (!result.isEmpty()) { saveLocation(result); } } }); alert.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Cancelled } }); alert.show(); }
From source file:com.example.run_tracker.ProfileFragment.java
@Override public void onClick(View arg0) { Log.v(TAG, "click"); AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Enter Password"); alert.setMessage("Please enter your password"); // Set an EditText view to get user input final EditText input = new EditText(getActivity()); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); alert.setView(input);/*from w ww . ja v a 2s .co m*/ alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String password = input.getText().toString(); String new_password = null; if (!mPassword1.getText().toString().equals(mPassword2.getText().toString())) { Toast.makeText(getActivity(), "Passwords dont match", Toast.LENGTH_LONG).show(); } else { if (isEmpty(mPassword1) || (isEmpty(mPassword2))) { new_password = password; } else { new_password = mPassword1.getText().toString(); } Make_edit_profile_request(password, new_password); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); }
From source file:com.xperia64.timidityae.FileBrowserFragment.java
public void getDir(String dirPath) { currPath = dirPath;/*from w w w .j a va 2s .c om*/ fname = new ArrayList<String>(); path = new ArrayList<String>(); if (currPath != null) { File f = new File(currPath); if (f.exists()) { File[] files = f.listFiles(); if (files != null && files.length > 0) { Arrays.sort(files, new FileComparator()); // System.out.println(currPath); if (!currPath.matches("[/]+")) { fname.add("../"); path.add(f.getParent() + "/"); mCallback.needFileBackCallback(true); } else { mCallback.needFileBackCallback(false); } for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.getName().startsWith(".") && !Globals.showHiddenFiles) || Globals.showHiddenFiles) { if (file.isFile()) { int dotPosition = file.getName().lastIndexOf("."); String extension = ""; if (dotPosition != -1) { extension = (file.getName().substring(dotPosition)).toLowerCase(Locale.US); if (extension != null) { if ((Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles) .contains("*" + extension + "*")) { path.add(file.getAbsolutePath()); fname.add(file.getName()); } } else if (file.getName().endsWith("/")) { path.add(file.getAbsolutePath() + "/"); fname.add(file.getName() + "/"); } } } else { path.add(file.getAbsolutePath() + "/"); fname.add(file.getName() + "/"); } } } } else { if (!currPath.matches("[/]+")) { fname.add("../"); path.add(f.getParent() + "/"); } } ArrayAdapter<String> fileList = new ArrayAdapter<String>(getActivity(), R.layout.row, fname); getListView().setFastScrollEnabled(true); getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> l, View v, final int position, long id) { localfinished = false; if (new File(path.get(position)).isFile() && Globals.isMidi(path.get(position))) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Convert to WAV File"); alert.setMessage( "Exports the MIDI/MOD file to WAV.\nNative Midi must be disabled in settings.\nWarning: WAV files are large."); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*"; if (IC.contains("*" + source.charAt(i) + "*")) { return ""; } } return null; } }; // Set an EditText view to get user input final EditText input = new EditText(getActivity()); input.setFilters(new InputFilter[] { filter }); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); if (!value.toLowerCase(Locale.US).endsWith(".wav")) value += ".wav"; String parent = path.get(position).substring(0, path.get(position).lastIndexOf('/') + 1); boolean aWrite = true; boolean alreadyExists = new File(parent + value).exists(); String needRename = null; String probablyTheRoot = ""; String probablyTheDirectory = ""; try { new FileOutputStream(parent + value, true).close(); } catch (FileNotFoundException e) { aWrite = false; } catch (IOException e) { e.printStackTrace(); } if (!alreadyExists && aWrite) new File(parent + value).delete(); if (aWrite && new File(parent).canWrite()) { value = parent + value; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) { // Write the file to getExternalFilesDir, then move it with the Uri // We need to tell JNIHandler that movement is needed. String[] tmp = Globals.getDocFilePaths(getActivity(), parent); probablyTheDirectory = tmp[0]; probablyTheRoot = tmp[1]; if (probablyTheDirectory.length() > 1) { needRename = parent.substring( parent.indexOf(probablyTheRoot) + probablyTheRoot.length()) + value; value = probablyTheDirectory + '/' + value; } else { value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value; } } else { value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value; } final boolean canWrite = aWrite; final String finalval = value; final String needToRename = needRename; final String probRoot = probablyTheRoot; if (new File(finalval).exists() || (new File(probRoot + needRename).exists() && needToRename != null)) { AlertDialog dialog2 = new AlertDialog.Builder(getActivity()).create(); dialog2.setTitle("Warning"); dialog2.setMessage("Overwrite WAV file?"); dialog2.setCancelable(false); dialog2.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (needToRename != null) { Globals.tryToDeleteFile(getActivity(), probRoot + needToRename); Globals.tryToDeleteFile(getActivity(), finalval); } else { Globals.tryToDeleteFile(getActivity(), finalval); } } else { new File(finalval).delete(); } saveWavPart2(position, finalval, needToRename); } }); dialog2.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog2.show(); } else { saveWavPart2(position, finalval, needToRename); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); return true; } else { } return false; } }); setListAdapter(fileList); } } }
From source file:com.yozio.demo.implementations.share.ShareButtonsActivity.java
public void showShareCommentDialog(Context context, final DialogFlowController controller) { final EditText text = new EditText(context); text.setMinLines(5);/*from ww w . ja v a2s . c o m*/ text.setGravity(Gravity.TOP); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Share"); builder.setMessage("Enter a comment (Optional)"); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { controller.onContinue(text.getText().toString()); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { controller.onCancel(); } }); AlertDialog dialog = builder.create(); dialog.setView(text); dialog.show(); }
From source file:edumsg.edumsg_android_app.MainActivity.java
/** * * The onCreate method first retrieves the sessionId and username from the parent {@link android.content.Intent}, * which is either created from a {@link LoginFragment} or a {@link RegisterFragment}. Afterwards, * it configures the action bar and performs view look-ups for the action bar buttons, followed * by setting the onClick listeners for the action bar buttons. Finally, it initializes the * properties, sets the onRefresh listener for the swipe refresh layout, and calls the method * {@link MainActivity#getFeed()}.//w w w.ja va 2 s. co m * */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sessionId = getIntent().getExtras().getString("sessionId"); username = getIntent().getExtras().getString("username"); setContentView(R.layout.activity_main); ButterKnife.bind(this); setSupportActionBar(toolbar); final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_main, null); final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(actionBarLayout); ImageButton homeButton = ButterKnife.findById(actionBarLayout, R.id.btn_home); final ImageButton searchButton = ButterKnife.findById(actionBarLayout, R.id.btn_search); ImageButton createButton = ButterKnife.findById(actionBarLayout, R.id.btn_create); ImageButton navButton = ButterKnife.findById(actionBarLayout, R.id.btn_nav); final ViewGroup searchLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_search, null); final SearchView searchView = ButterKnife.findById(searchLayout, R.id.search); final ImageButton backBtn = ButterKnife.findById(searchLayout, R.id.btn_back); homeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); searchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { actionBar.setCustomView(searchLayout); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager .getSearchableInfo(new ComponentName(MainActivity.this, SearchResultsActivity.class))); searchView.setQuery("", false); searchView.setIconified(false); searchView.setFocusable(true); searchView.requestFocusFromTouch(); } }); backBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { actionBar.setCustomView(actionBarLayout); InputMethodManager imm = (InputMethodManager) getApplicationContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow( MainActivity.this.getWindow().getDecorView().getRootView().getWindowToken(), 0); } }); createButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final EditText input = new EditText(MainActivity.this); input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); input.setLines(4); input.setSingleLine(false); input.setBackgroundDrawable(null); builder.setView(input); builder.setPositiveButton("Tweet", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { createTweet(input.getText().toString()); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { Button posBtn = dialog.getButton(AlertDialog.BUTTON_NEGATIVE); posBtn.setBackgroundColor(cPrimary); posBtn.setTextColor(Color.WHITE); final float scale = getApplicationContext().getResources().getDisplayMetrics().density; int pixels = (int) (10 * scale + 0.5f); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(0, 0, pixels, 0); posBtn.setLayoutParams(layoutParams); Button negBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE); negBtn.setBackgroundColor(cPrimary); negBtn.setTextColor(Color.WHITE); } }); dialog.show(); } }); navButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getSupportFragmentManager(); List<Fragment> fragments = fragmentManager.getFragments(); if (fragments != null) { for (Fragment fragment : fragments) { if (fragment instanceof NavigationFragment) return; } } NavigationFragment navigationFragment = new NavigationFragment(); // Bundle bundle = new_user Bundle(); // bundle.putInt("userId", userId); // mainActivityFragment.setArguments(bundle); fragmentManager.beginTransaction().add(android.R.id.content, navigationFragment) .addToBackStack("nav").commit(); // logout(); // launchMessages(); // Intent intent = new_user Intent(MainActivity.this, ProfileActivity.class); // intent.putExtra("username", getUsername()); // intent.putExtra("name", getName()); // intent.putExtra("avatar_url", getAvatar_url()); // intent.putExtra("bio", getBio()); // intent.putExtra("creatorId", getUserId()); // intent.putExtra("userId", getUserId()); // startActivity(intent); } }); recyclerView.setHasFixedSize(true); final float scale = getApplicationContext().getResources().getDisplayMetrics().density; int pixels = (int) (160 * scale + 0.5f); Paint paint = new Paint(); paint.setStrokeWidth(3.0f); paint.setColor(Color.rgb(220, 220, 220)); paint.setAntiAlias(true); recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).paint(paint).build()); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(linearLayoutManager); tweetObjects = new ArrayList<>(); rvAdapter = new RVAdapter(this, tweetObjects, sessionId); recyclerView.setAdapter(rvAdapter); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { tweetObjects.clear(); getFeed(); } }); getFeed(); }
From source file:nkarasch.repeatingreminder.gui.AlertView.java
@OnClick(R.id.text_label_display) public void labelOnClick() { final EditText input = new EditText(mContext); input.setSingleLine();//from ww w .j a va 2s . co m final int accentColor = getResources().getColor(R.color.accent); final int textColor = Color.WHITE; final AlertDialog labelDialog = new DialogBuilder(mContext).setTitle("Set Label").setTitleColor(accentColor) .setDividerColor(accentColor).setView(input) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mAlert.setLabel(input.getText().toString()); textLabel.setText(mAlert.getLabel()); stopAlert(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).create(); labelDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { labelDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(textColor); labelDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(textColor); } }); labelDialog.show(); }
From source file:com.support.android.designlibdemo.MatchedPetsDetailActivity.java
/**********************************************************************************************/ private AlertDialog createReportDialog(String titulo, String message) { // Instanciamos un nuevo AlertDialog Builder y le asociamos titulo y mensaje AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(titulo); alertDialogBuilder.setMessage(message); RelativeLayout linearLayout = new RelativeLayout(this); final EditText link = new EditText(this); link.setHint("Causa de la denuncia"); link.setWidth(750);// w ww.jav a 2 s.com linearLayout.addView(link); linearLayout.setPadding(70, 0, 0, 0); alertDialogBuilder.setView(linearLayout); link.invalidate(); linearLayout.invalidate(); final String petId = getIntent().getStringExtra("id"); final String reporterId = this.loginUser.getId(); // Creamos un nuevo OnClickListener para el boton OK que realice la conexion DialogInterface.OnClickListener listenerOk = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { reportComplain(petId, reporterId, link.getText().toString()); } }; // Creamos un nuevo OnClickListener para el boton Cancelar DialogInterface.OnClickListener listenerCancelar = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }; // Asignamos los botones positivo y negativo a sus respectivos listeners //OJO: estan al reves para que sea display si - no en vez de no - si alertDialogBuilder.setPositiveButton(R.string.dialogCancel, listenerCancelar); alertDialogBuilder.setNegativeButton(R.string.dialogSend, listenerOk); return alertDialogBuilder.create(); }
From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java
private TextView getEditView(final Feature feature, final String fieldName, EDataType type, String value) { final TextView editView; switch (type) { case DATE://ww w.jav a 2 s . c o m editView = new TextView(context); editView.setInputType(InputType.TYPE_CLASS_DATETIME); editView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FeaturePageAdapter.this.openDatePicker((EditText) view); } }); if (value == null || value.equals("")) { value = "____-__-__"; } break; default: editView = new EditText(context); break; } editView.setText(value); switch (type) { case DOUBLE: case FLOAT: editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); break; case PHONE: editView.setInputType(InputType.TYPE_CLASS_PHONE); break; case DATE: editView.setInputType(InputType.TYPE_CLASS_DATETIME); editView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FeaturePageAdapter.this.openDatePicker((TextView) view); } }); break; case INTEGER: editView.setInputType(InputType.TYPE_CLASS_NUMBER); break; default: break; } editView.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // ignore } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // ignore } public void afterTextChanged(Editable s) { String text = editView.getText().toString(); feature.setAttribute(fieldName, text); } }); return editView; }
From source file:cc.softwarefactory.lokki.android.fragments.PlacesFragment.java
private void renamePlaceDialog(final String placeName) { Log.d(TAG, "renamePlaceDialog"); AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); final EditText input = new EditText(getActivity()); String titleFormat = getResources().getString(R.string.rename_place); String title = String.format(titleFormat, placeName); dialog.setTitle(title).setMessage(R.string.write_place_name).setView(input) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override// www .j a v a2 s . c om public void onClick(DialogInterface dialog, int which) { String newName = input.getText().toString(); renamePlace(placeName, newName); dialog.dismiss(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); }