List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.example.skode6.scanenvy.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/* w w w . java 2s . co m*/ if (savedInstanceState != null) { try { ArrayList myArrayList = (ArrayList) getLastNonConfigurationInstance(); } catch (NullPointerException e) { List<Product> values = new ArrayList<Product>(); for (int i = 0; i < productList.size(); i++) { values.add((Product) savedInstanceState.getSerializable("product" + i)); } if (values != null) { lv = (RecyclerView) findViewById(R.id.list); lv.setHasFixedSize(false); LinearLayoutManager llm = new LinearLayoutManager(this); lv.setLayoutManager(llm); adapter = new ProductAdapter(this, values); lv.setAdapter(adapter); } } } else { productList = run.getProductList(); setListView(); } setToolBar(); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog = enterDialog(edit = new EditText(this)); edit = new EditText(this); fabToolbar = ((FabToolbar) findViewById(R.id.fab_toolbar)); findViewById(R.id.scan_code).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { fabToolbar.hide(); } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); }
From source file:com.luorrak.ouroboros.catalog.BoardListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_add_board: { final EditText edittext = new EditText(getActivity()); edittext.setInputType(InputType.TYPE_CLASS_TEXT); AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setMessage("New Board") .setTitle("Please enter a board name.").setView(edittext) .setPositiveButton("Add Board", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Add board to database, should consider doing some error checking as well. final String boardName = edittext.getText().toString(); Ion.with(getActivity()).load(ChanUrls.getCatalogUrl(boardName)).asString() .withResponse().setCallback(new FutureCallback<Response<String>>() { @Override public void onCompleted(Exception e, Response<String> stringResponse) { if (getActivity() != null) { if (e != null || stringResponse.getHeaders().code() == 404) { Snackbar.make(getView(), "Server Error! Does board exist?", Snackbar.LENGTH_LONG).show(); return; } InfiniteDbHelper infiniteDbHelper = new InfiniteDbHelper( getActivity()); infiniteDbHelper.insertBoardEntry(boardName, boardListAdapter.getCursor().getCount()); boardListAdapter.changeCursor(infiniteDbHelper.getBoardCursor()); } }// www.j av a 2 s . c o m }); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // what ever you want to do with No option. } }).create(); alertDialog.show(); break; } } return super.onOptionsItemSelected(item); }
From source file:org.asteroidos.sync.fragments.DeviceDetailFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { mFab = (FloatingActionButton) view.findViewById(R.id.fab); mFab.setOnClickListener(new View.OnClickListener() { @Override/*ww w . j ava 2s.c o m*/ public void onClick(View view) { if (mConnected) mConnectListener.onDisconnectRequested(); else mConnectListener.onConnectRequested(); } }); mConnectedText = (TextView) view.findViewById(R.id.info_connected); mConnectedImage = (ImageView) view.findViewById(R.id.info_icon_connected); mBatteryText = (TextView) view.findViewById(R.id.info_battery); mBatteryImage = (ImageView) view.findViewById(R.id.info_icon_battery); CardView weatherCard = (CardView) view.findViewById(R.id.card_view1); weatherCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(R.string.weather_settings); alert.setMessage(R.string.enter_city_name); final SharedPreferences settings = getActivity().getSharedPreferences(WeatherService.PREFS_NAME, 0); final EditText edittext = new EditText(getActivity()); int padding = (int) DeviceDetailFragment.this.getResources().getDisplayMetrics().density * 15; edittext.setPadding(padding, padding, padding, padding); edittext.setText( settings.getString(WeatherService.PREFS_CITY_NAME, WeatherService.PREFS_CITY_NAME_DEFAULT)); alert.setView(edittext); alert.setPositiveButton(getString(R.string.generic_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String cityName = edittext.getText().toString(); SharedPreferences.Editor editor = settings.edit(); editor.putString(WeatherService.PREFS_CITY_NAME, cityName); editor.apply(); } }); alert.show(); } }); CardView findCard = (CardView) view.findViewById(R.id.card_view2); findCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent("org.asteroidos.sync.NOTIFICATION_LISTENER"); i.putExtra("event", "posted"); i.putExtra("packageName", "org.asteroidos.sync"); i.putExtra("id", 0xa57e401d); i.putExtra("appName", getString(R.string.app_name)); i.putExtra("appIcon", ""); i.putExtra("summary", getString(R.string.watch_finder)); i.putExtra("body", getString(R.string.phone_is_searching)); getActivity().sendBroadcast(i); } }); CardView screenshotCard = (CardView) view.findViewById(R.id.card_view3); screenshotCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getActivity().sendBroadcast(new Intent("org.asteroidos.sync.SCREENSHOT_REQUEST_LISTENER")); } }); CardView notifSettCard = (CardView) view.findViewById(R.id.card_view4); notifSettCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getActivity(), R.string.not_supported, Toast.LENGTH_SHORT).show(); } }); CardView timeSyncCard = (CardView) view.findViewById(R.id.card_view5); timeSyncCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getActivity().sendBroadcast(new Intent("org.asteroidos.sync.TIME_SYNC_LISTENER")); } }); TextView unpairTextView = (TextView) view.findViewById(R.id.unpairTextView); unpairTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mDeviceListener.onDefaultDeviceUnselected(); } }); }
From source file:com.repay.android.adddebt.ChoosePersonFragment.java
public void addFriendByName() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle(R.string.fragment_addfriend_dialogtitle); final EditText nameEntry = new EditText(getActivity()); dialog.setView(nameEntry);//from ww w.j a va2 s . c o m dialog.setPositiveButton(R.string.fragment_addfriend_dialogokay, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String name = nameEntry.getText().toString(); try { if (name == null || name.equals("")) { throw new NullPointerException(); } Friend newFriend = new Friend(DatabaseHandler.generateRepayID(), null, name, new BigDecimal("0")); mDB.addFriend(newFriend); dataSetChanged(); } catch (SQLException e) { Toast.makeText(getActivity(), "Friend could not be added", Toast.LENGTH_SHORT).show(); } catch (NullPointerException e) { Toast.makeText(getActivity(), "No name entered, please try again", Toast.LENGTH_SHORT).show(); } } }); dialog.show(); }
From source file:com.example.android.directoryselection.DirectorySelectionFragment.java
@Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); rootView.findViewById(R.id.button_open_directory).setOnClickListener(new View.OnClickListener() { @Override/*w w w . j a v a2s . co m*/ public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_OPEN_DIRECTORY); } }); mCurrentDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_current_directory); mCreateDirectoryButton = (Button) rootView.findViewById(R.id.button_create_directory); mCreateDirectoryButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final EditText editView = new EditText(getActivity()); new AlertDialog.Builder(getActivity()).setTitle(R.string.create_directory).setView(editView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { createDirectory(mCurrentDirectoryUri, editView.getText().toString()); updateDirectoryEntries(mCurrentDirectoryUri); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_directory_entries); mLayoutManager = mRecyclerView.getLayoutManager(); mRecyclerView.scrollToPosition(0); mAdapter = new DirectoryEntryAdapter(new ArrayList<DirectoryEntry>()); mRecyclerView.setAdapter(mAdapter); }
From source file:com.google.android.agera.testapp.NotesFragment.java
@Override public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);/*from ww w .j a v a 2s . c o m*/ notesStore = notesStore(getContext().getApplicationContext()); pool = new RecycledViewPool(); final RowHandler<NoteGroup, List<Note>> rowHandler = rowBinder(pool, (r) -> new LinearLayoutManager(getContext(), HORIZONTAL, false), NoteGroup::getId, NoteGroup::getNotes, (r) -> dataBindingRepositoryPresenterOf(Note.class).layout(R.layout.text_layout).itemId(BR.note) .stableIdForItem(Note::getId).handler(BR.click, (Receiver<Note>) (note) -> { final EditText editText = new EditText(getContext()); editText.setId(R.id.edit); editText.setText(note.getNote()); new AlertDialog.Builder(getContext()).setTitle(R.string.edit_note).setView(editText) .setPositiveButton(R.string.edit, (d, i) -> notesStore.updateNote(note, editText.getText().toString())) .create().show(); }).handler(BR.longClick, (Receiver<Note>) notesStore::deleteNote).forList()); adapter = repositoryAdapter().add(notesStore.getNotesRepository(), repositoryPresenterOf(NoteGroup.class).layout(R.layout.note_group_layout) .stableIdForItem(NoteGroup::getId).bindWith(rowHandler).recycleWith(rowHandler).forList()) .build(); adapter.setHasStableIds(true); final DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); backgroundRepository = repositoryWithInitialValue(Result.<Bitmap>absent()).observe().onUpdatesPerLoop() .goTo(networkExecutor) .getFrom(() -> "http://www.gravatar.com/avatar/4df6f4fe5976df17deeea19443d4429d?s=" + Math.max(displayMetrics.heightPixels, displayMetrics.widthPixels)) .transform(url -> httpGetRequest(url).compile()).attemptTransform(httpFunction()) .orEnd(Result::failure).goTo(calculationExecutor).thenTransform(input -> { final byte[] body = input.getBody(); return absentIfNull(decodeByteArray(body, 0, body.length)); }).onDeactivation(SEND_INTERRUPT).compile(); }
From source file:com.wanderingcan.persistentsearch.PersistentSearchView.java
@SuppressWarnings("deprecation") private void initialize(Context context, AttributeSet attrs, int defStyleAttr) { mNavIcon = new ImageButton(context); mEndIcon = new ImageButton(context); mSearchText = new EditText(context); mSearchMenuView = new SearchMenuView(context); mDivider = new View(context); mDivider.setVisibility(GONE);// ww w. j a v a2 s . co m mPresenter = new SearchMenuPresenter(context, new SearchMenuListener()); mSearchMenuView.setAdapter(mPresenter.mAdapter); mSearchMenuView.addItemDecoration(new DividerItemDecoration(context, attrs)); int[] attr = { android.R.attr.listDivider }; TypedArray ta = context.obtainStyledAttributes(attr); Drawable divider = ta.getDrawable(0); ta.recycle(); mOpened = false; mShowClearDrawable = false; mShowMenu = true; //Set up CardView setUseCompatPadding(true); setFocusable(true); setFocusableInTouchMode(true); //Set up TextView if (Build.VERSION.SDK_INT >= 16) { mSearchText.setBackground(null); mNavIcon.setBackground(null); mEndIcon.setBackground(null); mDivider.setBackground(divider); } else { mSearchText.setBackgroundDrawable(null); mNavIcon.setBackgroundDrawable(null); mEndIcon.setBackgroundDrawable(null); mDivider.setBackgroundDrawable(divider); } mSearchText.setSingleLine(); mHintVisible = false; mSearchText.setOnFocusChangeListener(new SearchFocusListener()); mSearchText.setOnEditorActionListener(new EditTextEditorAction()); mSearchText.setImeOptions(EditorInfo.IME_ACTION_SEARCH); mSearchText.addTextChangedListener(new EditTextTextWatcher()); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersistentSearchView, defStyleAttr, 0); Drawable drawable = a.getDrawable(R.styleable.PersistentSearchView_navSrc); setNavigationDrawable(drawable); mNavIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); mNavIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mIconListener != null) { mIconListener.OnNavigationIconClick(); } } }); drawable = a.getDrawable(R.styleable.PersistentSearchView_endSrc); setEndDrawable(drawable); mClearDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_action_cancel); mEndIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); mEndIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mShowClearDrawable) { //Clears the text mSearchText.setText(EMPTY); } else { if (mIconListener != null) { mIconListener.OnEndIconClick(); } } } }); mHint = a.getText(R.styleable.PersistentSearchView_hint); mHintAlwaysVisible = a.getBoolean(R.styleable.PersistentSearchView_hintAlwaysActive, false); if (mHintAlwaysVisible) { mSearchText.setHint(mHint); } a.recycle(); Resources res = context.getResources(); int imageDimen = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_dimen); mImageMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_side_margin); int imageTopMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_top_margin); //Sets all of the locations of the views CardView.LayoutParams lpNav = generateDefaultLayoutParams(); lpNav.width = lpNav.height = imageDimen; CardView.LayoutParams lpEnd = (LayoutParams) generateLayoutParams(lpNav); lpNav.gravity = Gravity.START; lpEnd.gravity = Gravity.END; if (Build.VERSION.SDK_INT >= 17) { mNavIcon.setPaddingRelative(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin); mEndIcon.setPaddingRelative(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin); } else { mNavIcon.setPadding(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin); mEndIcon.setPadding(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin); } CardView.LayoutParams lpText = generateDefaultLayoutParams(); lpText.gravity = Gravity.TOP; lpText.height = lpNav.topMargin + lpNav.height; mTextMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_text_margin); if (Build.VERSION.SDK_INT >= 17) { lpText.setMarginStart(mTextMargin); lpText.setMarginEnd(mTextMargin); } else { lpText.leftMargin = lpText.rightMargin = mTextMargin; } lpText = setupSearchTextMargin(lpText); CardView.LayoutParams lpMenu = generateDefaultLayoutParams(); lpMenu.topMargin = lpNav.topMargin + lpNav.height; lpMenu.height = RecyclerView.LayoutParams.WRAP_CONTENT; CardView.LayoutParams lpDivider = generateDefaultLayoutParams(); if (divider != null) { lpDivider.height = divider.getIntrinsicHeight(); } lpDivider.topMargin = lpNav.topMargin + lpNav.height; //Adds the views to the PersistentSearchView addView(mNavIcon, lpNav); addView(mEndIcon, lpEnd); addView(mSearchText, lpText); addView(mSearchMenuView, lpMenu); addView(mDivider, lpDivider); }
From source file:com.variable.demo.api.fragment.ThermaFragment.java
/** * Builds a Dialog to ask the user to change the emissivity setting. *///from w w w . ja v a 2 s . c o m public void buildAndShowEmissivityDialog() { final EditText text = new EditText(getActivity()); text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); text.setHint("Enter a number for the emissivity of the surface."); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Enter an Emissivity Number"); builder.setView(text); builder.setPositiveButton("Change", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { String rawText = text.getText().toString(); try { Float emissivity_value = Float.parseFloat(rawText); PreferenceManager.getDefaultSharedPreferences(getActivity()).edit() .putFloat(PREF_EMISSIVITY_NUMBER, emissivity_value).commit(); mHandler.obtainMessage(MessageConstants.MESSAGE_EMISSIVITY_NUMBER_UPDATE).sendToTarget(); } catch (NumberFormatException e) { } } }); builder.setNegativeButton("Cancel", null); builder.create().show(); }
From source file:de.jerleo.samsung.knox.firewall.MainActivity.java
private void activateLicense() { final EditText edit = new EditText(MainActivity.this); final Toast invalid = Toast.makeText(this, getString(R.string.license_key_invalid), Toast.LENGTH_LONG); AlertDialog.Builder alert = new AlertDialog.Builder(this).setTitle(R.string.license_activation) .setMessage(R.string.license_key_paste).setView(edit) .setPositiveButton(R.string.license_activate, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String key = edit.getText().toString(); // Check for valid key length if (key.length() == 128) // Activate license and restart app elm.activateLicense(key); else invalid.show();/*from w w w.j a va 2 s .com*/ } }); alert.show(); }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(LT, "App created."); Events.intEnableDebug(1);/*from w ww . j ava2 s.c o m*/ // disable the titlebar requestWindowFeature(Window.FEATURE_NO_TITLE); // create a basic user interface LinearLayout panel = new LinearLayout(this); panel.setOrientation(LinearLayout.VERTICAL); setContentView(panel); EditText v = new EditText(this); v.setId(idTextView); v.setOnClickListener(this); panel.addView(v); // -- Button b = new Button(this); b.setText("Scan Input Devs"); b.setId(idButScan); b.setOnClickListener(this); panel.addView(b); // put list in a scroll view LinearLayout listLayout = new LinearLayout(this); listLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); m_lvDevices = new ListView(this); LayoutParams lvLayoutParam = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); m_lvDevices.setLayoutParams(lvLayoutParam); m_lvDevices.setId(idLVDevices); m_lvDevices.setDividerHeight(0); m_lvDevices.setFadingEdgeLength(0); m_lvDevices.setCacheColorHint(0); m_lvDevices.setAdapter(null); listLayout.addView(m_lvDevices); panel.addView(listLayout); // -- LinearLayout panelH = new LinearLayout(this); panelH.setOrientation(LinearLayout.HORIZONTAL); panel.addView(panelH); // -- m_selDevSpinner = new Spinner(this); m_selDevSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); m_selDevSpinner.setId(idSelSpin); m_selDevSpinner.setOnItemSelectedListener((OnItemSelectedListener) this); panelH.addView(m_selDevSpinner); // -- simulate key event b = new Button(this); b.setText(">Key"); b.setId(idButInjectKey); b.setOnClickListener(this); panelH.addView(b); // -- simulate touch event b = new Button(this); b.setText(">Tch"); b.setId(idButInjectTouch); b.setOnClickListener(this); panelH.addView(b); // -- m_tvMonitor = new TextView(this); m_tvMonitor.setText("Event Monitor stopped."); panel.addView(m_tvMonitor); // -- panelH = new LinearLayout(this); panelH.setOrientation(LinearLayout.HORIZONTAL); panel.addView(panelH); // -- b = new Button(this); b.setText("Monitor Start"); b.setId(idButMonitorStart); b.setOnClickListener(this); panelH.addView(b); // -- b = new Button(this); b.setText("Monitor Stop"); b.setId(idButMonitorStop); b.setOnClickListener(this); panelH.addView(b); // -- simulate test event b = new Button(this); b.setText(">Test"); b.setId(idButTest); b.setOnClickListener(this); panelH.addView(b); }