I have an EditText field and a CheckBox. The behavior I am looking for is 'one or the other should be valid'. (1) So if there's text in the EditText and if the user clicks the CheckBox, the EditText field should automatically be set to "". My code is if CheckBox.isChecked() EditText.setText(""), and this works as expected.
(2) Likewise, if the CheckBox is checked and if the user starts entering text in the EditText, the CheckBox needs to be unchecked. My code is on EditText..afterTextChanged listener, if CheckBox.isChecked() CheckBox.toggle(). This sort of seems to happen, but the EditText field doesn't let go of focus. So the next time, I try to click the CheckBox (#1), the EditText receives focus first even though I clicked the CheckBox, and then it clears the CheckBox, so I am never able to check the CheckBox, because the EditText keeps receiving focus and keeps unchecking the CheckBox.
Is there anyway I could make this happen? Please let me know. Thanks.
Related
I have a one textview two edittext fields. am using first for the taking input text from user .
for the Second view I made the focusable set to false and I wrote a onClickListener which pops up(Date Picker) so that user can set the date.
Scenario:
I first I click on the first edit text and I start typing some text when am done I click on the second edittext and a I get a popup(Dialog) I select the date and click set on the dialog.
My Problem here is : After setting the Date, focus is still in the first field.
What I have tried.
-- While implementing the onClickListener for the second edittext , I tried to change the focus to the textView.
textview.requestFocus();
but it din't work.
Is there a way I can change it ?
if you don't want to enter date manually.. than make that Edittext to Enable false.
editText.setEnabled(false);
editText.setFocusable(false);
editText.setInputType(InputType.TYPE_NULL);
and just set the text on edittext from datepicker dialog..
I have added two textview(id, name), two edittext and two buttons(edit,save) in every row of listview, When edit button is clicked both edittext appears in that row(visibility is set to gone in XML) now all I want to do is allow user to add some contents in edittext and on pressing save button those contents will be reflected in textview and edittext will be disappeared again.
On edit buttons click view two edittext are appearing as expected but as soon as I type in any of the edittext they are getting refreshed. In debug mode I have found out that as soon as I am typing in Edittext getView() method called again & again and that's the reason behind refresh.
I have implemented empty onclicklistner on edittext so that when it get touched and typed it will not call getView but thats not working and I know that's a stupid attempt to solve problem.
Please tell what to do so that when I click or type in edittext it will not call getView().
You have to off focus from xml of edittext and button
I have to do a ListView that contains on each item an EditText. If the EditText receives focus, I have to display a dialog - the condition is strictly for when the EditText receives focus and not when is pressed because it can be selected even if it is not pressed...
To do this I use a focus listener on the EditText but the onFocusChanged gets called three times instead on only one when the user presses the EditText, this means the dialog gets called twice...
This is the sequence of the calls:
Has focus
Lost focus
Has focus
I don't have any other special handling of the ListView or EditText .. so it should be from the system somehow, maybe because I am using the EditText on the ListView which is a focusable View too..
Does anyone have any ideas why is this happening and how can I "fix" this?
Thank you in advance.
I am building an edit in place listView. That is, the user is looking at a list of TextView items. Then the user touches one, indicating he'd like to edit it. The selected item is now shown as an EditText, in the same ListView as the other TextView items.
After this, the soft keyboard is shown, but the EditText has actually lost focus because of all the redrawing. I've got a handle on the EditText in SimpleCursorAdapter.getView(). But, calling EditText.requestFocus() is futile unless I can be sure the EditText is there on the screen.
In which method of which class will I be able to execute something like, getListView().findItemById(n).requestFocus(); ?
Thank you very much.
You can execute
getInstrumentation().waitForIdleSync()
to wait for all UI events.
I have a listview of different view types, including spinners and edittexts. I have a single focuslistener that listens for the onfocus lost event as I have to do some post processing. As a user may have to switch from one edittext to a next edittext by touch, and calling notifydatachanged in my focus lost event would trigger a redraw of the views, I used a variable to set the last focused edittext(whenever an edittext gains focus) so that I can requestfocus for the appropriate edittext in the getview call of the adapter.
Observation: If the spinners are touched first, they work fine. However if they are touched after any of the edittext has been focused and input with values, the spinners will not set the selected item on being touched.
Is anyone able to explain this observation or suggest a workaround?