how to make edittext and alertdialog has same width? - android

a alertdialog include a edittext
how to make edittext's width same with the alertdialog's (NO ABSOLUTE LAYOUT) ?

You can create a custom alertDialog and use the following code:
EditText myEditText = (EditText) activity.getViewById(R.id.myEditText);
myEditText.setLayoutParams(LayoutParams.MATCH_PARENT);
Give that a try.

Related

having trouble to make the layout of a dialog box

I wanted to make a Dialog box for simple signup page like this image
but I can't figure out how can I do this. I am basically struggling to make the cross icon to the right corner of the Dialog box.
Is there any library to make this?
Try this:
final Dialog exitBayDialog = new Dialog(getActivity());
exitBayDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
exitBayDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
exitBayDialog.setContentView(R.layout.your_dialog_layout);
final EditText etSearch = (EditText) exitBayDialog.findViewById(R.id.etVehicleNumber);
exitBayDialog.show();

Android AlertDialog.Builder Custom title bar with Edit text

Here is the issue, I want to create a custom alert dialog box with 4 parts,
Title Bar
Header part (Most of the time I plan to use EditText box for
searching purpose)
List item(Single click or Multi Click)
Footer part(Cancel or OK buttons)
I try do this using separate layout, but list view item not showing properly(shrinking). So then I plan to use AlertDialog and inside I have implemented ListView and footer button part in single LinerLayout and set it using setView method, it solved my list view and Footer issue.
Problem is I want to add Header part top of the list view.
Image Link : https://dl.dropboxusercontent.com/u/4048078/device-2013-07-31-141546.png
You can try this
Dialog dialog_help = new Dialog(getActivity());
dialog_help.setContentView(R.layout.title_multi_selectitems_dialog);
EditText et_1 = (EditText) dialog_help.findViewById(R.id.et_help_1);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
dialog_help.setCancelable(true);
dialog_help.setTitle(" Help ");
dialog_help.setCanceledOnTouchOutside(true);
dialog_help.show();
dialog_help.getWindow().setGravity(Gravity.CENTER);
dialog_help.getWindow().setLayout(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
It's not a good practice to set editBox in the title of the alert dialog.
To set title use setTitle and setIcon builder methods.
EditText it the control that's better to place in dialog,s body.
Use AlertDialog.Builder.setView(android.view.View) for this.

Changing contents of an EditText widget in AlertDialog without onPrepareDialog()

I'm using an AlertDialog with a custom view that contains an EditText widget. I want to change the contents of the EditText widget before the AlertDialog is shown. I know that this is usually done by overriding onPrepareDialog() and setting the text there. However, as far as I can see, this will not work in my specific case because I use AlertDialog.show() instead of Activity.showDialog().
So how should I do this with a dialog that is shown using AlertDialog.show()? One solution is to set the text after the dialog has been brought to the front, i.e.:
AlertDialog alertDialog = builder.create();
alertDialog.show();
EditText editText = (EditText) alertDialog.findViewById(R.id.text);
editText.setText("Foo bar");
However, I don't think that this is a nice solution because the dialog is first shown and then the text is set. I'd like to set the text before the dialog is actually shown.
Is there any way to achieve this? I cannot do it before alertDialog.show() because findViewById() returns null when called before alertDialog.show().
Thanks for any help!
AlertDialog alertDialog = builder.create();
alertDialog.show();
Since you have access to the AlertDialog.Builder object, simply change the layout before calling builder.create().
Addition
I have an EditText widget in my XML file which I inflate using builder.setView(inflater.inflate(R.layout.mydialog, null)). How do I change the text of this EditText widget without calling findViewById()?
Break that line into a series of commands. Specifically: inflate the XML, alter the layout, and pass it to setView().
View view = inflater.inflate(R.layout.mydialog, null);
EditText editText = (EditText) view.findViewById(R.id.text);
editText.setText("Foo bar");
builder.setView(view);

how to remove space if we hide edittext in android?

i am doing like these in my xml i using spinner.In spinner if i select other edittext should be visible.before that edittext space must be remove.
eidttext.setVisibility(android.view.View.INVISIBLE);
eidttext.setVisibility(android.view.View.GONE);
i want to remove space of the edittext when it is inVisible.if any have idea.
You use View.GONE to free the space for other widgets, View.INVISIBLE will keep the space, but make the widget, well, invisible. View's documentation
Try to use
View edittext;
Instead of Button edittext;
edittext.setVisibility(View.GONE);
This will help you
In XML use to hide a element with their shape height or width:
android:visibility="gone"

how to dynamically display the EditText?

i'm new to android. So can any one help me to get the following, when i enter the number in a EditText, the entered no.of EdidText should be appear dynamically. For example if i entered 3 in a EditText then, 3 EditText(no.of) have to be shown on the screen. How can i show this?
You need to add a TextWatcher to your EditText by calling EditText.addTextChangedListener(). Then in your TextWatcher wait for calls to afterTextChanged and count the characters and update your title. This will be easier if you make your Activity implement the the TextWatcher interface itself.
Add layout to your xml where you want to display the Edittext.
Then create the Layout variable e.g
LinearLayout ll = (LinearLayout)findViewById(R.id...);
and create new textboxes and add to the linearlayout e.g
EditText[] edit = new EditText[]();
EditText[] edit= new EditText[entered number];
initialize the variables in the loop by new Edittext(context);
and add each one to the Layout
`ll.addView(edit[iterator]);`

Categories

Resources