android diasble EditText but not able to bring back to life - android

hi I am disabling an edittext during part of my program but later I want to bring it back on line, and its not accepting focus or text entry. here is the code
Disable
intTextValue.setEnabled(false);
intTextValue.setInputType(InputType.TYPE_NULL);
intTextValue.setFocusable(false);
intSeek.setEnabled(false);
intType.setClickable(false);
Enable
intTextValue.setEnabled(true);
intTextValue.setInputType(InputType.TYPE_CLASS_NUMBER);
intTextValue.setFocusable(true);
intSeek.setEnabled(true);
intType.setClickable(true);
You will notice 3 variable names there intTextValue is the EditText, intSeek is a seek bar and intType is a spinner, the seekbar and spinner are both find, just editText which starts off enabled, after disable wont reenable.
help will be much appreciated.
thanks.

try this :
Disable :
EditText edt=(EditText)findViewById(R.id.editboxtxt);
edt.setEnabled(false);
edt.setInputType(InputType.TYPE_NULL);
edt.setFocusableInTouchMode(false);
edt.clearFocus();
Enable :
EditText edt=(EditText)findViewById(R.id.editboxtxt);
edt.setEnabled(true);
edt.setInputType(InputType.TYPE_CLASS_NUMBER);
edt.setFocusableInTouchMode(true);
edt.requestFocus();

Related

Enable Edittext after disabling it

OnButtonClick listener I want to disable the EditText to edit, and then turn it on again.
With below two lines I disabled EditText
editTextWight.setEnabled(false);
editTextWight.setFocusable(false);
But when I try to turn it back fails. The keyboard does not open.
editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
editTextWight.setClickable(true);
editTextWight.setEnabled(true);
Please help me to enable the EditText.
You can try this two lines that work for my project code:
editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
I do this for example afterTextChanged() is called because I had to disable this EditText first then enable it later!
So, just try it with ONLY two method calls above instead of all the four.
Good luck and let me know if it worked!
Thank you Eenvincible and sajan. Your answers togheter help me to solve my problem. I enabled the editing window with these 4 methods.
editTextWight.setEnabled(true);
editTextWight.setInputType(InputType.TYPE_CLASS_NUMBER);
editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
to disable edit text use
editTextWight.setEnabled(false);
editTextWight.setInputType(InputType.TYPE_NULL);
editTextWight.setFocusable(false);
to enable edit text use
editTextWight.setEnabled(true);
editTextWight.setInputType(InputType.TYPE_CLASS_TEXT);
editTextWight.setFocusable(true);

Can't get Search box to work in App Inventor 2

No matter what I do the ResponseLabel.Text won't change after hitting the search button. The keyboard does hide after I hit the search button though.
My code for the search button is
When Search Button Click
Call Search Box.Request Focus
Call Search Box.Hide Keyboard
Code for Search Box is:
When SearchBox Got Focus/
if/ is in list?/ thing/ Search Box.Text/
list/ get GlobalMetalList/
then/ set ResponseLabel.Text to/ Check Metal Page
else/ set ResponseLabel.Text to/ Not Found.
Move the blocks from the GotFocus event into the Click event

Editable textview on click

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);
}
}

How can I react when an EditText is being focused?

I have an EditText that the user can write in, when the app starts there is already a string in the EditText. When the user clicks the EditText it becomes focused and the curser is where the user clicked the EditText text box.
I know that the code for setting the curser to the start is :
editText.setSelection(0);
But I don't know where to put this code, I tried to it in beforeTextChanged but it didn't do the job.
You can do this by setting an putting an OnFocusChangedListener. You'd do something like this:
et.setOnFocusChangeListener(new View.OnFocusChangeListener(){
public void onFocusChange(View view, boolean hasFocus){
if(hasFocus){
((EditText)view).setSelection(0);
}
}
});
Where et is the text edit you want to set the listener on.
Full-discolsure: haven't tried this code out myself.
While there is probably a way to do this, I'm not entirely sure it's the best user experience, because when the user taps a text box at a specific spot, they really expect the cursor to be there. Imagine for instance if the user sees "abcd" written there and wants to edit that to "abcde", so they figure "I'll just tap at the end and append an 'e'". Imagine the user's frustration when that doesn't work as expected.
If you expect the user to edit the textbox, I'd consider leaving it empty. If you are using the existing text as a hint ("email#example.com"), it's probably a better idea to indicate that in some other way.

Android: How to enable my button back if EditText is not empty?

I have 2 EditTexts; 01 and 02. My button will be disabled once the activity is started and when these two EditText contain text, the button has to be enabled again. However my button is always disabled and can't enable it using button.setEnabled(true);.
Can anyone help me with this?
summit.setEnabled(false);
buttonEnable();
public void buttonEnable(){
if (feedback.length()>0 && email.length()>0){
summit.setEnabled(true);
}else{
summit.setEnabled(false);
}
}
You're correct about needing a TextWatcher. The afterTextChanged(Editable) method is the one you're interested in for something like this. Call your buttonEnable() method from it, and add the TextWatcher to any applicable text fields. (Looks like feedback and email from your sample.)
One easy way can also be to set onKeyListener to your editText(), then if there is something in editText(), set button enable if nothing disable it.

Categories

Resources