List of usage examples for android.widget LinearLayout setPadding
public void setPadding(int left, int top, int right, int bottom)
From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java
private View handleTrains(final int position, View convertView, @NonNull final ViewGroup parent) { // Train//ww w.ja v a 2 s .co m final Station station = stations.get(position); final Set<TrainLine> trainLines = station.getLines(); TrainViewHolder viewHolder; if (convertView == null || convertView.getTag() == null) { final LayoutInflater vi = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = vi.inflate(R.layout.list_nearby, parent, false); viewHolder = new TrainViewHolder(); viewHolder.resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results); viewHolder.stationNameView = (TextView) convertView.findViewById(R.id.station_name); viewHolder.imageView = (ImageView) convertView.findViewById(R.id.icon); viewHolder.details = new HashMap<>(); viewHolder.arrivalTime = new HashMap<>(); convertView.setTag(viewHolder); } else { viewHolder = (TrainViewHolder) convertView.getTag(); } viewHolder.stationNameView.setText(station.getName()); viewHolder.imageView .setImageDrawable(ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_train_white_24dp)); for (final TrainLine trainLine : trainLines) { if (trainArrivals.indexOfKey(station.getId()) != -1) { final List<Eta> etas = trainArrivals.get(station.getId()).getEtas(trainLine); if (etas.size() != 0) { final LinearLayout llv; boolean cleanBeforeAdd = false; if (viewHolder.details.containsKey(trainLine)) { llv = viewHolder.details.get(trainLine); cleanBeforeAdd = true; } else { final LinearLayout llh = new LinearLayout(context); llh.setOrientation(LinearLayout.HORIZONTAL); llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0); llv = new LinearLayout(context); llv.setOrientation(LinearLayout.VERTICAL); llv.setPadding(line1PaddingColor, 0, 0, 0); llh.addView(llv); viewHolder.resultLayout.addView(llh); viewHolder.details.put(trainLine, llv); } final List<String> keysCleaned = new ArrayList<>(); for (final Eta eta : etas) { final Stop stop = eta.getStop(); final String key = station.getName() + "_" + trainLine.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(); if (viewHolder.arrivalTime.containsKey(key)) { final RelativeLayout insideLayout = viewHolder.arrivalTime.get(key); final TextView timing = (TextView) insideLayout.getChildAt(2); if (cleanBeforeAdd && !keysCleaned.contains(key)) { timing.setText(""); keysCleaned.add(key); } final String timingText = timing.getText() + eta.getTimeLeftDueDelay() + " "; timing.setText(timingText); } else { final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout insideLayout = new RelativeLayout(context); insideLayout.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableParam.addRule(RelativeLayout.RIGHT_OF, lineId); availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final TextView stopName = new TextView(context); final String destName = eta.getDestName() + ": "; stopName.setText(destName); stopName.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey_5)); stopName.setLayoutParams(availableParam); int availableId = Util.generateViewId(); stopName.setId(availableId); final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId); availableValueParam.setMargins(0, 0, 0, 0); final TextView timing = new TextView(context); final String timeLeftDueDelay = eta.getTimeLeftDueDelay() + " "; timing.setText(timeLeftDueDelay); timing.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey)); timing.setLines(1); timing.setEllipsize(TruncateAt.END); timing.setLayoutParams(availableValueParam); insideLayout.addView(lineIndication); insideLayout.addView(stopName); insideLayout.addView(timing); llv.addView(insideLayout); viewHolder.arrivalTime.put(key, insideLayout); } } } } } convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, station.getId(), station.getStopsPosition().get(0).getLatitude(), station.getStopsPosition().get(0).getLongitude())); return convertView; }
From source file:jp.watnow.plugins.dialog.Notification.java
/** * // w ww. jav a2 s. c o m * @param message * @param title * @param buttonLabels * @param defaultTexts * @param callbackContext */ public synchronized void login(final String title, final String message, final JSONArray buttonLabels, final JSONArray defaultTexts, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { LinearLayout layout = new LinearLayout(cordova.getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(10, 0, 10, 0); final EditText usernameInput = new EditText(cordova.getActivity()); usernameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL); final EditText passwordInput = new EditText(cordova.getActivity()); passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); try { usernameInput.setHint("ID"); usernameInput.setText(defaultTexts.getString(0)); passwordInput.setHint("PASSWORD"); passwordInput.setText(defaultTexts.getString(1)); } catch (JSONException e1) { } layout.addView(usernameInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(passwordInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setView(layout); final JSONObject result = new JSONObject(); try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", usernameInput.getText()); result.put("input2", passwordInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } try { dlg.setPositiveButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:org.mewx.wenku8.fragment.NavigationDrawerFragment.java
private void updateNavigationBar() { // test navigation bar exist Point navBar = LightTool.getNavigationBarSize(getActivity()); // Toast.makeText(getActivity(), "width = " + navBar.x + "; height = " + navBar.y, Toast.LENGTH_SHORT).show(); LinearLayout ll = (LinearLayout) mainActivity.findViewById(R.id.main_menu_bottom_layout); if (navBar.y == 0) ll.setPadding(0, 0, 0, 0); // hide else/* w ww. j a va 2 s . c o m*/ ll.setPadding(0, 0, 0, navBar.y); // show }
From source file:nit.contact.views.PagerSlidingTabStrip.java
private void addTabView(int position) { LinearLayout view = new LinearLayout(getContext()); view.setOrientation(LinearLayout.VERTICAL); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setGravity(Gravity.CENTER);//from w ww . java2 s. co m view.setPadding(tabPadding, indicatorHeight, tabPadding, indicatorHeight); View tab = ((IconTabProvider) mPager.getAdapter()).getView(position); view.addView(tab); addTab(position, view); }
From source file:eu.hydrologis.geopaparazzi.maptools.FeaturePageAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { final Feature feature = featuresList.get(position); int bgColor = context.getResources().getColor(R.color.formbgcolor); int textColor = context.getResources().getColor(R.color.formcolor); ScrollView scrollView = new ScrollView(context); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);/*w ww . j a v a 2 s .c o m*/ scrollLayoutParams.setMargins(10, 10, 10, 10); scrollView.setLayoutParams(scrollLayoutParams); scrollView.setBackgroundColor(bgColor); LinearLayout linearLayoutView = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); int margin = 10; layoutParams.setMargins(margin, margin, margin, margin); linearLayoutView.setLayoutParams(layoutParams); linearLayoutView.setOrientation(LinearLayout.VERTICAL); int padding = 10; linearLayoutView.setPadding(padding, padding, padding, padding); scrollView.addView(linearLayoutView); List<String> attributeNames = feature.getAttributeNames(); List<String> attributeValues = feature.getAttributeValuesStrings(); List<String> attributeTypes = feature.getAttributeTypes(); for (int i = 0; i < attributeNames.size(); i++) { final String name = attributeNames.get(i); String value = attributeValues.get(i); String typeString = attributeTypes.get(i); DataType type = DataType.getType4Name(typeString); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(padding, padding, padding, padding); textView.setText(name); textView.setTextColor(textColor); // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); linearLayoutView.addView(textView); final EditText editView = new EditText(context); LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); editViewParams.setMargins(margin, 0, margin, 0); editView.setLayoutParams(editViewParams); editView.setPadding(padding * 2, padding, padding * 2, padding); editView.setText(value); // editView.setEnabled(!isReadOnly); editView.setFocusable(!isReadOnly); // editView.setTextAppearance(context, android.R.style.TextAppearance_Medium); if (isReadOnly) { editView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { String text = editView.getText().toString(); FeatureUtilities.viewIfApplicable(v.getContext(), text); return false; } }); } 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); 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(name, text); } }); linearLayoutView.addView(editView); } /* * add also area and length */ if (feature.getOriginalArea() > -1) { TextView areaTextView = new TextView(context); areaTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); areaTextView.setPadding(padding, padding, padding, padding); areaTextView.setText("Area: " + areaLengthFormatter.format(feature.getOriginalArea())); areaTextView.setTextColor(textColor); TextView lengthTextView = new TextView(context); lengthTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); lengthTextView.setPadding(padding, padding, padding, padding); lengthTextView.setText("Length: " + areaLengthFormatter.format(feature.getOriginalLength())); lengthTextView.setTextColor(textColor); linearLayoutView.addView(areaTextView); linearLayoutView.addView(lengthTextView); } container.addView(scrollView); return scrollView; }
From source file:com.bhb27.isu.Props.java
private void EditProps(String[] props) { LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); linearLayout.setPadding(30, 20, 30, 20); TextView descriptionText = new TextView(getActivity()); descriptionText.setText(getString(R.string.props_any_edit_dialog_summary)); linearLayout.addView(descriptionText); ScrollView scrollView = new ScrollView(getActivity()); scrollView.setPadding(0, 0, 0, 10);/*from w w w. j a va 2 s . co m*/ linearLayout.addView(scrollView); LinearLayout editLayout = new LinearLayout(getActivity()); editLayout.setOrientation(LinearLayout.VERTICAL); scrollView.addView(editLayout); final AppCompatEditText[] EditProps = new AppCompatEditText[props.length]; final AppCompatCheckBox[] ForceBP = new AppCompatCheckBox[props.length]; final TextView[] descriptionAboveText = new TextView[props.length]; final TextView[] descriptionBelowText = new TextView[props.length]; for (int i = 0; i < props.length; i++) { descriptionAboveText[i] = new TextView(getActivity()); descriptionAboveText[i].setText(String.format(getString(R.string.empty), props[i])); editLayout.addView(descriptionAboveText[i]); EditProps[i] = new AppCompatEditText(getActivity()); EditProps[i].setText(Tools.getprop(props[i])); editLayout.addView(EditProps[i]); descriptionBelowText[i] = new TextView(getActivity()); descriptionBelowText[i].setText(getString(R.string.props_any_edit_dialog_already_bp)); ForceBP[i] = new AppCompatCheckBox(getActivity()); ForceBP[i].setText(getString(R.string.props_any_edit_dialog_force_bp)); if (Tools.PropIsinbp(props[i], getActivity())) editLayout.addView(descriptionBelowText[i]); else editLayout.addView(ForceBP[i]); } new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle) .setTitle(getString(R.string.props_any_edit_dialog_title)).setView(linearLayout) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { return; } }).setPositiveButton(getString(R.string.apply), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { String finalmenssage = "\n", edited; for (int i = 0; i < props.length; i++) { edited = EditProps[i].getText().toString(); if (edited.isEmpty()) { finalmenssage = finalmenssage + String.format(getString(R.string.edited_text_ro), props[i]); } else if (edited.equals(Tools.getprop(props[i]))) finalmenssage = finalmenssage + String.format(getString(R.string.edited_text_equals), props[i]); else { if (((AppCompatCheckBox) ForceBP[i]).isChecked()) Tools.resetprop(executableFilePath, props[i], edited, getActivity(), true); else Tools.resetprop(executableFilePath, props[i], edited, getActivity(), false); finalmenssage = finalmenssage + String.format(getString(R.string.edited_text_ok), props[i]); save_prop(props[i], edited); } finalmenssage = finalmenssage + "\n"; } finaldialogro(finalmenssage); return; } }).show(); }
From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { final Feature feature = featuresList.get(position); int bgColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formbgcolor); int textColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formcolor); ScrollView scrollView = new ScrollView(context); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);//w w w . java 2 s. co m scrollLayoutParams.setMargins(10, 10, 10, 10); scrollView.setLayoutParams(scrollLayoutParams); scrollView.setBackgroundColor(bgColor); LinearLayout linearLayoutView = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); int margin = 10; layoutParams.setMargins(margin, margin, margin, margin); linearLayoutView.setLayoutParams(layoutParams); linearLayoutView.setOrientation(LinearLayout.VERTICAL); int padding = 10; linearLayoutView.setPadding(padding, padding, padding, padding); scrollView.addView(linearLayoutView); List<String> attributeNames = feature.getAttributeNames(); List<String> attributeValues = feature.getAttributeValuesStrings(); List<String> attributeTypes = feature.getAttributeTypes(); for (int i = 0; i < attributeNames.size(); i++) { final String name = attributeNames.get(i); String value = attributeValues.get(i); String typeString = attributeTypes.get(i); EDataType type = EDataType.getType4Name(typeString); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(padding, padding, padding, padding); textView.setText(name); textView.setTextColor(textColor); // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); linearLayoutView.addView(textView); final TextView editView = getEditView(feature, name, type, value); LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); editViewParams.setMargins(margin, 0, margin, 0); editView.setLayoutParams(editViewParams); editView.setPadding(padding * 2, padding, padding * 2, padding); editView.setFocusable(!isReadOnly); if (isReadOnly) { editView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { String text = editView.getText().toString(); FeatureUtilities.viewIfApplicable(v.getContext(), text); return false; } }); } linearLayoutView.addView(editView); } /* * add also area and length */ if (feature.getOriginalArea() > -1) { TextView areaTextView = new TextView(context); areaTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); areaTextView.setPadding(padding, padding, padding, padding); areaTextView.setText(context.getString(eu.geopaparazzi.core.R.string.area_colon) + areaLengthFormatter.format(feature.getOriginalArea())); areaTextView.setTextColor(textColor); TextView lengthTextView = new TextView(context); lengthTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); lengthTextView.setPadding(padding, padding, padding, padding); lengthTextView.setText(context.getString(eu.geopaparazzi.core.R.string.length_colon) + areaLengthFormatter.format(feature.getOriginalLength())); lengthTextView.setTextColor(textColor); linearLayoutView.addView(areaTextView); linearLayoutView.addView(lengthTextView); } container.addView(scrollView); return scrollView; }
From source file:com.chuger.bithdayapp.view.auth.AuthDialog.java
private void setUpWebView(final int margin) { final LinearLayout webViewContainer = new LinearLayout(getContext()); mWebView = new WebView(getContext()); mWebView.setVerticalScrollBarEnabled(false); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setWebViewClient(new AuthDialog.FbWebViewClient()); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl(mUrl);/*from www .j a v a 2 s . co m*/ mWebView.setLayoutParams(FILL); mWebView.setVisibility(View.INVISIBLE); webViewContainer.setPadding(margin, margin, margin, margin); webViewContainer.addView(mWebView); mContent.addView(webViewContainer); }
From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java
private void deletePasswordDialog(final String password) { if (password.isEmpty()) { Utils.toast(getString(R.string.set_password_first), getActivity()); return;// w w w . j ava 2 s .c o m } mDeletePassword = password; LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding)); linearLayout.setPadding(padding, padding, padding, padding); final AppCompatEditText mPassword = new AppCompatEditText(getActivity()); mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); mPassword.setHint(getString(R.string.password)); linearLayout.addView(mPassword); new Dialog(getActivity()).setView(linearLayout) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (!mPassword.getText().toString().equals(Utils.decodeString(password))) { Utils.toast(getString(R.string.password_wrong), getActivity()); return; } Prefs.saveString("password", "", getActivity()); if (mFingerprint != null) { mFingerprint.setEnabled(false); } } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { mDeletePassword = null; } }).show(); }
From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java
private void editPasswordDialog(final String oldPass) { mOldPassword = oldPass;//w ww . ja va 2 s . co m LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding)); linearLayout.setPadding(padding, padding, padding, padding); final AppCompatEditText oldPassword = new AppCompatEditText(getActivity()); if (!oldPass.isEmpty()) { oldPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); oldPassword.setHint(getString(R.string.old_password)); linearLayout.addView(oldPassword); } final AppCompatEditText newPassword = new AppCompatEditText(getActivity()); newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); newPassword.setHint(getString(R.string.new_password)); linearLayout.addView(newPassword); final AppCompatEditText confirmNewPassword = new AppCompatEditText(getActivity()); confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); confirmNewPassword.setHint(getString(R.string.confirm_new_password)); linearLayout.addView(confirmNewPassword); new Dialog(getActivity()).setView(linearLayout) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (!oldPass.isEmpty() && !oldPassword.getText().toString().equals(Utils.decodeString(oldPass))) { Utils.toast(getString(R.string.old_password_wrong), getActivity()); return; } if (newPassword.getText().toString().isEmpty()) { Utils.toast(getString(R.string.password_empty), getActivity()); return; } if (!newPassword.getText().toString().equals(confirmNewPassword.getText().toString())) { Utils.toast(getString(R.string.password_not_match), getActivity()); return; } if (newPassword.getText().toString().length() > 32) { Utils.toast(getString(R.string.password_too_long), getActivity()); return; } Prefs.saveString("password", Utils.encodeString(newPassword.getText().toString()), getActivity()); if (mFingerprint != null) { mFingerprint.setEnabled(true); } } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { mOldPassword = null; } }).show(); }