actually i am displaying a pop up with ok cancel button when user clicks on edit text.
My problem is when ever user double clicks on edit text two pop up comes. so if user has selected any value from pop up its second pop up still remain there.
I don't know how to deal with it.
Any help will appreciated. thanks in advance.
This is my layout
<EditText
android:id="#+id/date_control"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/bg_edit_text"
android:focusableInTouchMode="false"
android:inputType="none"
android:editable="false"
android:clickable="true"
android:layout_marginRight="5dp" />
My java class calling the controller
datePicker = (EditText) findView(R.id.date_control);
datePicker.setOnClickListener(myControllerClass);
its controller
MyDialog myDialog = new myDialog(activity, "Select Date",
date, DateTimeDialog.DATE_PICKER);
myDialog.show();
If you keep a field reference to your dialog you could check to see if its already showing
if(myDialog == null) {
myDialog = new myDialog(activity, "Select Date",
date, DateTimeDialog.DATE_PICKER);
}
if(!myDialog.isShowing()) {
myDialog.show();
}
You just need to set your edittext clickable false after click (means your dialog gets display) then on dialog dismiss you can again make your edittext clickable true.
you have to set this property programmatically .. for EditText properties link..
Hope this explanation works for you..
Related
I am using TextInputLayout for input fields.
But when I add an icon at the end of the field, a problem occurs.
If I click on the field, the TextInputLayout gets focus AND the end icon get focus after it. Now if I want to leave that field, one back press will only removes the focus from the end icon, then I have to press it a second time so the field will lose focus and close the keyboard.
GIF of the behavior
TextInputLayout XML code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fieldsInputField"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxBackgroundColor="#android:color/transparent"
app:hintTextColor="#color/primaryColor"
android:textColorHint="#color/hintColor"
app:startIconDrawable="#drawable/ic_list"
app:startIconTint="#color/primaryColor"
app:endIconDrawable="#drawable/ic_list"
app:endIconTint="#color/primaryColor"
android:hint="#string/hint">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:labelFor="#id/fieldsInputField"
android:maxLines="2" />
</com.google.android.material.textfield.TextInputLayout>
Kotlin code:
fieldsInputField.setEndIconOnClickListener {
// create a new field
val newTextInputLayout = LayoutInflater.from(requireContext()).inflate(
R.layout.fields_item, null) as TextInputLayout
// add the new field id to the list of ids
newTextInputLayout.id = View.generateViewId()
fieldsIds.add(newTextInputLayout.id)
newTextInputLayout.hint = "${newTextInputLayout.hint}"
setTextInputLayoutHandler(newTextInputLayout, SignUpRegex.dummy, "")
// add 'remove field' button to the new field
newTextInputLayout.setEndIconOnClickListener {
fieldsLayout.removeView(newTextInputLayout)
fieldsIds.remove(newTextInputLayout.id)
}
// add the new field to the layout
fieldsLayout.addView(newTextInputLayout)
}
I want to show an AlertDialog containing an EditText that auomtically capitalizes words.
Following this question and that one, I managed to get the AlertDialog show the keyboard automatically when the dialog is shown, and also capitalize the first letter when the user clicks on the EditText. But until the user clicks, the keyboard shows in lowercase mode.
How can I make the keyboard open automatically in upper-case (auto-capitalize words) mode?
My relevant code is as follows:
input = new EditText(context);
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Also tried to requestFocus() in the dialog's onShowListener but it didn't help.
You just need to use the following code after your AlertDialog declaration.
AlertDialog.Builder alert = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK);
final EditText edittext = new EditText(getApplicationContext());
// Just use it here, there is much more options in the link below
edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
Look for other options here
A workaround that worked for me was to avoid using setMessage(), and adding the message into my own view instead (using setView()).
I've got a problem. Since I am a newbie to develop Android apps, I suppose that I did not get all the concepts right.
The problem is:In my dialog, after entering all the information and pushing the "Ok" button, I would like to get what I just entered into the TextEdit field. But when I try to
get that EditText on okButton.onClickListener through findViewById(R.id.myTextEditId) I got Null instead of instance.
Here is some code:
Dialog's XML (part where I define EditText) :
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:inputType="textMultiLine"
android:maxLines="3"
android:hint="#string/add_new_note_hint">
<requestFocus />
</EditText>
Here is the code, where NPE accours:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
View dialogView = getLayoutInflater().inflate(R.layout.add_note_dialog,null);
dialogBuilder.setTitle(R.string.add_dialog_title)
.setPositiveButton(R.string.add_dialog_pos_but, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
EditText et = (EditText) findViewById(R.id.editText1); //this is where I get null instead of real instance.
}
})
Why am I getting this and what is the right way (best practice) to process widget's data in some callback method ? (how to fix)
Thank you very much, for your time on my issue!
dialogView.findViewById will solve this
The problem is that findViewById searches the current view hierarchy. If you call this from your Activity, then it searches in your current activity's view hierarchy whereas you actually want to search your dialog's:
EditText et = (EditText) dialogView.findViewById(R.id.editText1);
You'll probably need to make dialogView final as well.
I have a screen with textviews now i want to make this editable on click of that
i tried one solution using edittext making it as transparent background but initially it will show cursor and the click is not recognizing properly,if i set focusbaleintouchmode to false in xml it is not getting focus.but some how the click is not working properly as expected.first is this correct approach?
expected result is textview should be there once user clicks on it it should be editable once user clicks outside it it should be not editable. any sample code will helps me a lot.sorry for my english
Thanks in advance
finally i got one solution using below code
in xml edit text i gave foucasbletouchmode to false which makes click works properly after that with in onclick
et.setFocusable(true);
et.setEnabled(true);
et.setFocusableInTouchMode(true);
et.requestFocus();
to lose focus
et.setFocusable(false);
et.setClickable(true);
et.clearFocus();
You can use the below code :
private makeEditable(boolean isEditable,EditText et){
if(isEditable){
et.setBackgroundDrawable("Give the textbox background here");//You can store it in some variable and use it over here while making non editable.
et.setFocusable(true);
et.setEnabled(true);
et.setClickable(true);
et.setFocusableInTouchMode(true);
et.setKeyListener("Set edit text key listener here"); //You can store it in some variable and use it over here while making non editable.
}else{
et.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
et.setFocusable(false);
et.setClickable(false);
et.setFocusableInTouchMode(false);
et.setEnabled(false);
et.setKeyListener(null);
}
}
I have a TextView with the following assignment code:
Answer1TextView = (TextView) findViewById(R.id.editText1);
Answer1TextView.setOnClickListener(answer1TextViewListener);
and here is my onClickListener:
private OnClickListener answer1TextViewListener = new OnClickListener()
{
public void onClick(View v)
{
if(Answer1Win){
Toast.makeText(QuizScreen.this,"Correct ",2).show();
} else
{
Toast.makeText(QuizScreen.this,"Incorrect, Pick Another Answer",2).show();
}
}
};
My problem is the Toast only is displayed after a double tap. I cannot find a setting the drives this behavior, what could be set wrong to not display after a single tap.
The first click just sets the focus to the TextBox then the second click actually gets handled as a click. Rather than using an onClickListener, you may have better luck with an onFocusChangeListener
As Chris said, the first tap focuses the TextView and the second tap clicks it.
Setting android:focusableInTouchMode="false" fixes the problem for touchscreens but without breaking functionality for non-touchscreen devices.
If you were to simply use android:focusable="false" that would prevent, for example, d-pad users from clicking the view at all.
The issue may be that textIsSelectable is true. Set textIsSelectable="false" for the TextView in XML.
The correct way to do that is android:clickable="true"
use OnTouchListener instead onFocusListener triggers twice when you enter and leaves the key