List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.example.flashcards.wizardpager.wizard.ui.TopicChoiceFragment.java
private void getNewTopicName() { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Vlote sekci"); alert.setMessage("Jmno"); // Set an EditText view to get user input final EditText input = new EditText(getActivity()); alert.setView(input);/* w w w .ja va 2 s. co m*/ alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); createNewTopic(value); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); }
From source file:org.pixmob.appengine.client.demo.DemoActivity.java
@Override protected Dialog onCreateDialog(int id) { if (NO_ACCOUNT_DIALOG == id) { final AlertDialog d = new AlertDialog.Builder(this).setTitle(R.string.error).setCancelable(false) .setMessage(R.string.no_account_error).setPositiveButton(R.string.quit, new OnClickListener() { @Override/*www .jav a2 s .co m*/ public void onClick(DialogInterface dialog, int which) { finish(); } }).create(); return d; } if (PROGRESS_DIALOG == id) { final ProgressDialog d = new ProgressDialog(this); d.setMessage(getString(R.string.connecting_to_appengine)); d.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { loginTask.cancel(true); // release resources when the task is canceled loginTask = null; } }); return d; } if (MODIFY_APPSPOT_BASE_DIALOG == id) { final EditText input = new EditText(this); input.setSelectAllOnFocus(true); input.setText(prefs.getString(APPSPOT_BASE_PREF, defaultAppspotBase)); final AlertDialog d = new AlertDialog.Builder(this).setView(input) .setTitle(R.string.enter_appspot_instance_name) .setPositiveButton(R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { appspotBase = trimToNull(input.getText().toString()); if (appspotBase == null) { appspotBase = defaultAppspotBase; } appspotBaseView.setText(appspotBase); storeFields(); } }).create(); return d; } return super.onCreateDialog(id); }
From source file:com.google.android.agera.testapp.NotesFragment.java
@Nullable @Override/*from w w w . j a v a2s .co m*/ public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.notes_fragment, container, false); // Find the clear button and wire the click listener to call the clear notes updatable view.findViewById(R.id.clear).setOnClickListener(v -> notesStore.clearNotes()); // Find the add button and wire the click listener to show a dialog that in turn calls the add // note from text from the notes store when adding notes view.findViewById(R.id.add).setOnClickListener(v -> { final EditText editText = new EditText(v.getContext()); editText.setId(R.id.edit); new AlertDialog.Builder(v.getContext()).setTitle(R.string.add_note).setView(editText) .setPositiveButton(R.string.add, (d, i) -> { notesStore.insertNoteFromText(editText.getText().toString()); }).create().show(); }); // Setup the recycler view using the repository adapter recyclerView = (RecyclerView) view.findViewById(R.id.result); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final ImageView imageView = (ImageView) view.findViewById(R.id.background); updatable = () -> backgroundRepository.get().ifSucceededSendTo(imageView::setImageBitmap); return view; }
From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.alarm_preferences); pref = getSharedPreferences("AppPref", MODE_PRIVATE); email = getIntent().getStringExtra("email"); Log.d("? ???!!! ", "" + email); Bundle bundle = getIntent().getExtras(); if (bundle != null && bundle.containsKey("alarm")) { setMathAlarm((Alarm) bundle.getSerializable("alarm")); } else {/*from w ww . ja va 2 s. co m*/ setMathAlarm(new Alarm()); } if (bundle != null && bundle.containsKey("adapter")) { setListAdapter((AlarmPreferenceListAdapter) bundle.getSerializable("adapter")); } else { setListAdapter(new AlarmPreferenceListAdapter(this, getMathAlarm())); } getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { final AlarmPreferenceListAdapter alarmPreferenceListAdapter = (AlarmPreferenceListAdapter) getListAdapter(); final AlarmPreference alarmPreference = (AlarmPreference) alarmPreferenceListAdapter .getItem(position); AlertDialog.Builder alert; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (alarmPreference.getType()) { case BOOLEAN: CheckedTextView checkedTextView = (CheckedTextView) v; boolean checked = !checkedTextView.isChecked(); ((CheckedTextView) v).setChecked(checked); switch (alarmPreference.getKey()) { case ALARM_ACTIVE: alarm.setAlarmActive(checked); break; case ALARM_VIBRATE: alarm.setVibrate(checked); if (checked) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); } break; } alarmPreference.setValue(checked); break; case STRING: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(AlarmPreferencesActivity.this); input.setText(alarmPreference.getValue().toString()); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { alarmPreference.setValue(input.getText().toString()); if (alarmPreference.getKey() == Key.ALARM_NAME) { alarm.setAlarmName(alarmPreference.getValue().toString()); } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] items = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < items.length; i++) items[i] = alarmPreference.getOptions()[i]; alert.setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (alarmPreference.getKey()) { case ALARM_DIFFICULTY: Alarm.Difficulty d = Alarm.Difficulty.values()[which]; alarm.setDifficulty(d); break; case ALARM_TONE: alarm.setAlarmTonePath(alarmPreferenceListAdapter.getAlarmTonePaths()[which]); if (alarm.getAlarmTonePath() != null) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } else { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); mediaPlayer.reset(); } try { // mediaPlayer.setVolume(1.0f, 1.0f); mediaPlayer.setVolume(0.2f, 0.2f); mediaPlayer.setDataSource(AlarmPreferencesActivity.this, Uri.parse(alarm.getAlarmTonePath())); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setLooping(false); mediaPlayer.prepare(); mediaPlayer.start(); // Force the mediaPlayer to stop after 3 // seconds... if (alarmToneTimer != null) alarmToneTimer.cancel(); alarmToneTimer = new CountDownTimer(3000, 3000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e) { } } }; alarmToneTimer.start(); } catch (Exception e) { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e2) { } } } break; default: break; } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case MULTIPLE_LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] multiListItems = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < multiListItems.length; i++) multiListItems[i] = alarmPreference.getOptions()[i]; boolean[] checkedItems = new boolean[multiListItems.length]; for (Alarm.Day day : getMathAlarm().getDays()) { checkedItems[day.ordinal()] = true; } alert.setMultiChoiceItems(multiListItems, checkedItems, new OnMultiChoiceClickListener() { @Override public void onClick(final DialogInterface dialog, int which, boolean isChecked) { Alarm.Day thisDay = Alarm.Day.values()[which]; if (isChecked) { alarm.addDay(thisDay); } else { // Only remove the day if there are more than 1 // selected if (alarm.getDays().length > 1) { alarm.removeDay(thisDay); } else { // If the last day was unchecked, re-check // it ((AlertDialog) dialog).getListView().setItemChecked(which, true); } } } }); alert.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case TIME: TimePickerDialog timePickerDialog = new TimePickerDialog(AlarmPreferencesActivity.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hours, int minutes) { Calendar newAlarmTime = Calendar.getInstance(); newAlarmTime.set(Calendar.HOUR_OF_DAY, hours); newAlarmTime.set(Calendar.MINUTE, minutes); newAlarmTime.set(Calendar.SECOND, 0); alarm.setAlarmTime(newAlarmTime); alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }, alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY), alarm.getAlarmTime().get(Calendar.MINUTE), true); timePickerDialog.setTitle(alarmPreference.getTitle()); timePickerDialog.show(); default: break; } } }); }
From source file:com.example.anish.myapplication.MainActivity.java
private void showInputDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Change city"); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT); builder.setView(input);//from w w w .jav a 2 s .c om builder.setPositiveButton("Go", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { changeCity(input.getText().toString()); } }); builder.show(); }
From source file:com.github.nutomic.pegasus.activities.ProfileList.java
/** * Show an AlertDialog to edit the name of a profile. * //from w w w. j a v a2s . c om * @param profile ID of the profile to rename. */ private void renameProfile(final long profile, String name) { final EditText input = new EditText(this); input.setText(name); input.setSingleLine(); AlertDialog alert = new AlertDialog.Builder(this).setTitle(R.string.profilelist_rename).setView(input) .setPositiveButton(android.R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { new UpdateTask() { @Override protected Long doInBackground(Void... params) { ContentValues cv = new ContentValues(); cv.put(ProfileColumns.NAME, input.getText().toString()); Database.getInstance(ProfileList.this).getWritableDatabase().update( ProfileColumns.TABLE_NAME, cv, ProfileColumns._ID + " = ?", new String[] { Long.toString(profile) }); return null; } }.execute((Void) null); } }).setNegativeButton(android.R.string.cancel, null).create(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); alert.show(); input.selectAll(); }
From source file:An.stop.AnstopActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog;/* w ww. j a va2 s .c o m*/ switch (id) { case ABOUT_DIALOG: AlertDialog.Builder aboutBuilder = new AlertDialog.Builder(this); aboutBuilder.setMessage(R.string.about_dialog).setCancelable(true).setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog = aboutBuilder.create(); break; case SAVE_DIALOG: AlertDialog.Builder saveBuilder = new AlertDialog.Builder(this); saveBuilder.setTitle(R.string.save); saveBuilder.setMessage(R.string.save_dialog); final EditText input = new EditText(this); saveBuilder.setView(input); saveBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // TODO save! Toast toast = Toast.makeText(getApplicationContext(), R.string.saved_succes, Toast.LENGTH_SHORT); toast.show(); } }); saveBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); saveBuilder.setCancelable(false); dialog = saveBuilder.create(); break; default: dialog = null; } return dialog; }
From source file:com.java2s.intents4.IntentsDemo4Activity.java
void addRow(final LinearLayout layout, String label, String hintStr, boolean addRadioGroup) { LinearLayout.LayoutParams rowLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1); if (addRadioGroup) { editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1); }/* w w w.j av a 2s .c o m*/ LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); row.setGravity(Gravity.CENTER_VERTICAL); TextView textView = new TextView(this); textView.setText(label); row.addView(textView); EditText editText = new EditText(this); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); editText.setHint(hintStr); editText.setLayoutParams(editTextLayoutParams); if (!isFirstTime) { editText.requestFocus(); } row.addView(editText); if (addRadioGroup) { LinearLayout groupLayout = new LinearLayout(this); groupLayout.setOrientation(LinearLayout.VERTICAL); groupLayout.setGravity(Gravity.CENTER_HORIZONTAL); RadioGroup group = new RadioGroup(this); group.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT)); final Button patternButton = new Button(this); patternButton.setText(pathPatterns[0]); patternButton.setTextSize(8); patternButton.setLayoutParams(buttonLayoutParams); patternButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String patternButtonText = patternButton.getText().toString().trim(); if (patternButtonText.equals(pathPatterns[0])) { patternButton.setText(pathPatterns[1]); } else if (patternButtonText.equals(pathPatterns[1])) { patternButton.setText(pathPatterns[2]); } else if (patternButtonText.equals(pathPatterns[2])) { patternButton.setText(pathPatterns[0]); } } }); groupLayout.addView(patternButton); row.addView(groupLayout); } Button button = new Button(this); button.setTextSize(10); button.setTypeface(null, Typeface.BOLD); button.setText("X"); button.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); button.setLayoutParams(buttonLayoutParams); button.setOnClickListener(new OnClickListener() { public void onClick(View view) { layout.removeView((LinearLayout) view.getParent()); } }); row.addView(button); row.setLayoutParams(rowLayoutParams); layout.addView(row); }
From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_PROGRESS: final ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(getText(R.string.login_message_authenticating)); dialog.setIndeterminate(true);// w w w . j a va 2 s.co m dialog.setCancelable(true); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { Log.i(TAG, "dialog cancel has been invoked"); if (mAuthenticationTask != null) { mAuthenticationTask.cancel(true); mAuthenticationTask = null; finish(); } } }); return dialog; case DIALOG_SET_BASE_URL: final EditText baseUrl = new EditText(this); baseUrl.setText(getString(R.string.default_api_url)); final AlertDialog.Builder db = new AlertDialog.Builder(this); return db.create(); default: return null; } }
From source file:com.raspi.chatapp.ui.chatting.ChatListFragment.java
/** * this function will make sure the ui looks right and reload everything. * Yeah, it is inefficient calling it every time a little detail has * changed but atm I don't care as this won't be as loaded as the * ChatFragment.// www.j a v a2 s . co m */ private void initUI() { // create the chatArrayAdapter caa = new ChatArrayAdapter(getContext(), R.layout.chat_list_entry); ListView lv = (ListView) getView().findViewById(R.id.main_listview); lv.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_NORMAL); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // on click open the corresponding chat ChatEntry chatEntry = caa.getItem(position); mListener.onChatOpened(chatEntry.buddyId, chatEntry.name); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) { // on long click rename the chat --> look ChatFragment final EditText newName = new EditText(getActivity()); newName.setText(caa.getItem(position).name); String title = getResources().getString(R.string.change_name_title) + " " + caa.getItem(position).name; // the dialog with corresponding title and message and with the // pre filled editText new AlertDialog.Builder(getContext()).setTitle(title).setMessage(R.string.change_name) .setView(newName).setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // rename the chat and reinitialize the ui MessageHistory messageHistory = new MessageHistory(getContext()); String buddyId = caa.getItem(position).buddyId; String name = newName.getText().toString(); messageHistory.renameChat(buddyId, name); initUI(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // there is a cancel button too... } }).show(); return true; } }); // set the data lv.setAdapter(caa); MessageHistory messageHistory = new MessageHistory(getContext()); // retrieve the chats and add them to the listView ChatEntry[] entries = messageHistory.getChats(); for (ChatEntry entry : entries) { if (entry != null) caa.add(entry); } // the swipe refresh layout final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getActivity() .findViewById(R.id.swipe_refresh); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // make everything related to refreshing in a background thread new Thread(new RefreshRunnable(new Handler(), swipeRefreshLayout)).start(); } }); // make sure that the no internet text displays the emojicon correctly EmojiconTextView textView = (EmojiconTextView) getActivity().findViewById(R.id.no_internet_text); textView.setText( String.format(getActivity().getResources().getString(R.string.no_internet), "\uD83D\uDE28")); // set the title actionBar.setTitle("ChatApp"); // make sure that there is no subtitle actionBar.setSubtitle(null); }