List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.fb.android.remindmap.parselogin.ParseLoginActivity.java
private void updatePhoneNumber(final ParseUser user) { AlertDialog.Builder phoneNumberDialog = new AlertDialog.Builder(this); phoneNumberDialog.setTitle("Phone Number").setMessage("Please enter a 10 digit phone number"); final EditText phoneNumberInput = new EditText(this); if (user.get("phoneNumber") != null) { phoneNumberInput.setText(user.get("phoneNumber").toString()); }/*from w w w .j av a 2s . c om*/ phoneNumberInput.setInputType(InputType.TYPE_CLASS_PHONE); phoneNumberInput.setPadding(100, 0, 100, 25); phoneNumberDialog.setView(phoneNumberInput); phoneNumberDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { user.put("phoneNumber", phoneNumberInput.getText().toString()); user.pinInBackground("phoneNumber", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { user.saveEventually(); } else { Toast.makeText(getApplicationContext(), "Error saving: " + e.getMessage(), Toast.LENGTH_LONG).show(); } } }); if (user.get("phoneNumber") == null) { Toast.makeText(getApplicationContext(), "Please enter a valid 10-digit phone number", Toast.LENGTH_LONG).show(); updatePhoneNumber(user); } if (user.get("phoneNumber") != null) { if (user.get("phoneNumber").toString().length() != 10) { Toast.makeText(getApplicationContext(), "Please enter a valid 10-digit phone number", Toast.LENGTH_LONG).show(); updatePhoneNumber(user); } if (user.get("phoneNumber").toString().length() == 10) { finish(); } } } }) .setIcon(android.R.drawable.ic_menu_call).show(); }
From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.cmenu_dlist_delete: ClaimListController.removeDestination(destAdaptor.getItem(info.position), theClaim); destAdaptor.notifyDataSetChanged(); return true; case R.id.cmenu_dlist_edit: //show a dialog for editing destinations final EditText enterLocation = new EditText(this); final EditText enterReason = new EditText(this); enterLocation.setText(destAdaptor.getItem(info.position).getLocation()); enterReason.setText(destAdaptor.getItem(info.position).getReason()); enterLocation.setHint("Enter location"); enterReason.setHint("Enter reason"); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(enterLocation); linearLayout.addView(enterReason); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setView(linearLayout);/* w w w . j a v a 2 s . co m*/ alert.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { destAdaptor.getItem(info.position).setLocation(enterLocation.getText().toString()); destAdaptor.getItem(info.position).setReason(enterReason.getText().toString()); destAdaptor.notifyDataSetChanged(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); return true; case R.id.cmenu_dlist_geolocation: adaptorPos = info.position; AlertDialog.Builder alertGl = new AlertDialog.Builder(this); alertGl.setPositiveButton("GPS", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (GeoLocationController.checkGPSEnabled()) { GeoLocationController.setDestinationGeoLocationGPS(destAdaptor.getItem(info.position)); destAdaptor.notifyDataSetChanged(); } } }); alertGl.setNegativeButton("Map", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Open map view \ Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this); startActivityForResult(intent, GET_GEOLOCATION_CODE); } }); alertGl.show(); return true; case R.id.cmenu_delete_tag: ClaimListController.removeTag(theClaim, tagAdaptor.getItem(info.position)); tagAdaptor.notifyDataSetChanged(); return true; case R.id.cmenu_rename_tag: //create a Alert dialog for editing tag name final TextView enterTag = new AutoCompleteTextView(this); enterTag.setHint("Enter tag"); AlertDialog.Builder alertTag = new AlertDialog.Builder(this); alertTag.setView(enterTag); alertTag.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { tagAdaptor.getItem(info.position).setName(enterTag.getText().toString()); tagAdaptor.notifyDataSetChanged(); } }); alertTag.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alertTag.show(); return true; default: return super.onContextItemSelected(item); } }
From source file:com.vuze.android.remote.fragment.OpenOptionsGeneralFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FragmentActivity activity = getActivity(); Intent intent = activity.getIntent(); if (AndroidUtils.DEBUG) { Log.d(TAG, activity + "] onCreateview " + this); }/*w w w . ja v a2 s .com*/ final Bundle extras = intent.getExtras(); if (extras == null) { Log.e(TAG, "No extras!"); } else { String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY); if (remoteProfileID != null) { sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity); } torrentID = extras.getLong("TorrentID"); } if (activity instanceof TorrentOpenOptionsActivity) { ourActivity = (TorrentOpenOptionsActivity) activity; } topView = inflater.inflate(R.layout.frag_openoptions_general, container, false); ImageButton btnEditDir = (ImageButton) topView.findViewById(R.id.openoptions_btn_editdir); ImageButton btnEditName = (ImageButton) topView.findViewById(R.id.openoptions_btn_editname); tvName = (TextView) topView.findViewById(R.id.openoptions_name); tvSaveLocation = (TextView) topView.findViewById(R.id.openoptions_saveloc); tvFreeSpace = (TextView) topView.findViewById(R.id.openoptions_freespace); CompoundButton btnPositionLast = (CompoundButton) topView.findViewById(R.id.openoptions_sw_position); CompoundButton btnStateQueued = (CompoundButton) topView.findViewById(R.id.openoptions_sw_state); if (ourActivity != null) { if (btnPositionLast != null) { btnPositionLast.setChecked(ourActivity.isPositionLast()); btnPositionLast.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ourActivity.setPositionLast(isChecked); } }); } if (btnStateQueued != null) { btnStateQueued.setChecked(ourActivity.isStateQueued()); btnStateQueued.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ourActivity.setStateQueued(isChecked); } }); } } final Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); if (torrent == null) { getActivity().finish(); VuzeEasyTracker.getInstance(getActivity()).logError("Torrent doesn't exist", TAG); return topView; } if (torrent.containsKey(TransmissionVars.FIELD_TORRENT_DOWNLOAD_DIR)) { updateFields(torrent); } else { sessionInfo.executeRpc(new RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.getTorrent(TAG, torrentID, Collections.singletonList(TransmissionVars.FIELD_TORRENT_DOWNLOAD_DIR), new TorrentListReceivedListener() { @Override public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps, List<?> removedTorrentIDs) { AndroidUtils.runOnUIThread(OpenOptionsGeneralFragment.this, new Runnable() { @Override public void run() { updateFields(torrent); } }); } }); } }); } if (btnEditDir != null) { btnEditDir.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); DialogFragmentMoveData.openMoveDataDialog(torrent, sessionInfo, getFragmentManager()); } }); } if (btnEditName != null) { if (sessionInfo.getSupportsTorrentRename()) { btnEditName.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Builder builder = new AlertDialog.Builder(getActivity()); final TextView textView = new EditText(getActivity()); textView.setText(tvName.getText()); textView.setSingleLine(); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { builder.setInverseBackgroundForced(true); } builder.setView(textView); builder.setTitle(R.string.change_name_title); builder.setMessage(R.string.change_name_message); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String newName = textView.getText().toString(); tvName.setText(newName); sessionInfo.executeRpc(new RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.setDisplayName(TAG, torrentID, newName); } }); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.create().show(); } }); } else { btnEditName.setVisibility(View.GONE); } } return topView; }
From source file:org.floens.chan.ui.controller.DrawerController.java
@Override public void onPinLongClocked(final Pin pin) { LinearLayout wrap = new LinearLayout(context); wrap.setPadding(dp(16), dp(16), dp(16), 0); final EditText text = new EditText(context); text.setSingleLine();/*from w ww .ja va2 s.c o m*/ text.setText(pin.loadable.title); wrap.addView(text, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); AlertDialog dialog = new AlertDialog.Builder(context) .setPositiveButton(R.string.action_rename, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String value = text.getText().toString(); if (!TextUtils.isEmpty(value)) { pin.loadable.title = value; Chan.getWatchManager().updatePin(pin); } } }).setNegativeButton(R.string.cancel, null).setTitle(R.string.action_rename_pin).setView(wrap) .create(); AndroidUtils.requestKeyboardFocus(dialog, text); dialog.show(); }
From source file:nz.ac.auckland.lablet.script.components.TextComponent.java
@Override public View createView(Context context, Fragment parent) { ScriptTreeNodeSheetBase.Counter counter = this.component.getCounter("QuestionCounter"); // Note: we have to do this programmatically because findViewById would find the wrong child // items if there is more than one text question. LinearLayout layout = new LinearLayout(context); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.setOrientation(LinearLayout.VERTICAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color, null)); } else {/*from w w w . j a v a 2 s. co m*/ layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color)); } TextView textView = new TextView(context); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(android.R.style.TextAppearance_Medium); } else { textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); } question_num = counter.increaseValue(); textView.setText("Q" + question_num + ": " + text); EditText editText = new EditText(context); editText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editText.setText(answer); editText.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) { } @Override public void afterTextChanged(Editable editable) { answer = editable.toString(); update(); } }); layout.addView(textView); layout.addView(editText); return layout; }
From source file:org.cocos2dx.lib.Cocos2dxEditBoxDialog.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000)); LinearLayout layout = new LinearLayout(mParentActivity); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); mTextViewTitle = new TextView(mParentActivity); LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10); mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); layout.addView(mTextViewTitle, textviewParams); mInputEditText = new EditText(mParentActivity); LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10); layout.addView(mInputEditText, editTextParams); setContentView(layout, layoutParams); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); mInputMode = mMsg.inputMode;/*from w w w. j a v a2s. c om*/ mInputFlag = mMsg.inputFlag; mReturnType = mMsg.returnType; mMaxLength = mMsg.maxLength; mTextViewTitle.setText(mMsg.title); mInputEditText.setText(mMsg.content); int oldImeOptions = mInputEditText.getImeOptions(); mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI); oldImeOptions = mInputEditText.getImeOptions(); switch (mInputMode) { case kEditBoxInputModeAny: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE; break; case kEditBoxInputModeEmailAddr: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; break; case kEditBoxInputModeNumeric: mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED; break; case kEditBoxInputModePhoneNumber: mInputModeContraints = InputType.TYPE_CLASS_PHONE; break; case kEditBoxInputModeUrl: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; break; case kEditBoxInputModeDecimal: mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED; break; case kEditBoxInputModeSingleLine: mInputModeContraints = InputType.TYPE_CLASS_TEXT; break; default: break; } if (mIsMultiline) { mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE; } mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints); switch (mInputFlag) { case kEditBoxInputFlagPassword: mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; break; case kEditBoxInputFlagSensitive: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; break; case kEditBoxInputFlagInitialCapsWord: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS; break; case kEditBoxInputFlagInitialCapsSentence: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; break; case kEditBoxInputFlagInitialCapsAllCharacters: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; break; default: break; } mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints); switch (mReturnType) { case kKeyboardReturnTypeDefault: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); break; case kKeyboardReturnTypeDone: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE); break; case kKeyboardReturnTypeSend: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND); break; case kKeyboardReturnTypeSearch: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH); break; case kKeyboardReturnTypeGo: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO); break; default: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); break; } if (mMaxLength > 0) { mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxLength) }); } Handler initHandler = new Handler(); initHandler.postDelayed(new Runnable() { public void run() { mInputEditText.requestFocus(); mInputEditText.setSelection(mInputEditText.length()); openKeyboard(); } }, 200); mInputEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // if user didn't set keyboard type, // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP' if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null && event.getAction() == KeyEvent.ACTION_DOWN)) { //Log.d("EditBox", "actionId: "+actionId +",event: "+event); mParentActivity.setEditBoxResult(mInputEditText.getText().toString()); closeKeyboard(); dismiss(); return true; } return false; } }); }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java
/** Handles item selections */ @Override/*from ww w . java2 s . c om*/ public boolean onOptionsItemSelected(MenuItem item) { Resources res = this.getResources(); switch (item.getItemId()) { case android.R.id.home: closeStudyOptions(); return true; case MENU_PREFERENCES: startActivityForResult(new Intent(this, Preferences.class), StudyOptionsFragment.PREFERENCES_UPDATE); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE); } return true; case MENU_ROTATE: if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } return true; case MENU_NIGHT: SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this); if (preferences.getBoolean("invertedColors", false)) { preferences.edit().putBoolean("invertedColors", false).commit(); item.setIcon(R.drawable.ic_menu_night); } else { preferences.edit().putBoolean("invertedColors", true).commit(); item.setIcon(R.drawable.ic_menu_night_checked); } return true; case DeckPicker.MENU_CREATE_DYNAMIC_DECK: StyledDialog.Builder builder = new StyledDialog.Builder(StudyOptionsActivity.this); builder.setTitle(res.getString(R.string.new_deck)); mDialogEditText = new EditText(StudyOptionsActivity.this); ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames(); int n = 1; String cramDeckName = "Cram 1"; while (names.contains(cramDeckName)) { n++; cramDeckName = "Cram " + n; } mDialogEditText.setText(cramDeckName); // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter }); builder.setView(mDialogEditText, false, false); builder.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { long id; Bundle initialConfig = new Bundle(); try { initialConfig.putString("searchSuffix", "'deck:" + AnkiDroidApp.getCol().getDecks().current().getString("name") + "'"); id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString()); AnkiDroidApp.getCol().getDecks().get(id); } catch (JSONException e) { throw new RuntimeException(e); } loadContent(false, initialConfig); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); builder.create().show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override//from w w w .jav a 2 s .c o m public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beacon.expectedStability != null && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beacon.status = Beacon.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beacon.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }
From source file:com.bt.download.android.gui.util.UIUtils.java
public static EditText buildEditTextWithType(Context context, KeyListener keyListener, String text) { EditText editText = new EditText(context); editText.setKeyListener(keyListener); editText.setText(text);/*w ww . j a v a2s . c om*/ return editText; }
From source file:com.notifry.android.SourceList.java
/** * Helper function to show a dialog to ask for a source name. *//* w ww.j a v a2s . c o m*/ private void askForSourceName() { final EditText input = new EditText(this); new AlertDialog.Builder(this).setTitle(getString(R.string.create_source)) .setMessage(getString(R.string.create_source_message)).setView(input) .setPositiveButton(getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); if (value.length() > 0) { // Fire it off to the create source // function. createSource(value.toString()); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { // No need to take any action. } }).show(); }