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?
Related
I have a list of items held in a RecyclerView. Now, these items each have an EditText view in them.
I'd like to activate (set focus to) the EditText of an item when it's added the first time. How do I do that?
To identify the relevant view, keep a reference to the newly added item in the adapter and when it's view is bound, call view.requestFocus() (see the docs).
To get focus and show the keyboard you would write something like this:
if(myEditText.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
You need to clear focus if another EditText gets focus. This can be done with
myEditText.clearFocus()
Take note, that all the EditText views should have set their onFocusChangeListener to the same listener
so i'm adding a row to ListView. This row contains an EditText, Spinner and a Button.
I can select the last added row and it's corresponding EditText.
Now I want to focus this object and edit it.
I've already tried with an InputManager, a handler, invalidating the whole view.
But it never focuses on the object.
However when I add a OnFocusChangeListener() to the EditText, requestFocus() triggers the event.
Just the UI is not being updated. Same goes for changing the text. While debugging the value of the EditText are changed, but the UI doesn't get updated.
Didn't try by myself, but can you try this way please.
View childView = (View) listView.getChildAt(INTEGEER_POSITION);
EditText editTextTFocus = (EditText) childView.findViewById(R.id.etxId);
editTextTFocus.requestFocus();
Idea is that, to get specific vieew from listview with specific position.
And then access that particular view and giving it focus.
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 developing an application for Android, and for that I am trying to make a ListView act in such a way, that when a user presses an empty entry, he can start typing text directly into that empty entry, and that when the user touches any other part of the screen, it is saved. Is there a way to do this? I was thinking of using onClick somehow, but I have no concrete approach.
Here is one basic, general approach:
For each row of the ListView, create a layout that has a visible TextView and a EditText with the visibility set to gone.
Use an onClickListener for each row to swap the visibilities of the TextView and EditText (respectively, gone and visible) when the row is selected.
Track the active row for clicks to another row or background.
When the active row changes, set the value of the EditText to the TextView and return them to their original visible states.
Other approach that could be taken is using the View.OnFocusChangeListener and the TextWatcher you can get more detail about them here http://developer.android.com/reference/packages.html
I am on Android 2.1 and I have one multi column Custom listview Using BaseAdapter with an editable edittext at the end of the listview. If the data in the listview do not contain the data of user choice then user should be able to enter data. If the data is already there in the list user will be able to select the data using custom selector. If a selection is made in the list view and user wanted to enter data in the text field at the bottom after selection then the marker in the list view should be unselected. I tried to use onclick() method on edit text using click listener. First time when it is clicked, edit text is getting focus and onclick() method is not fired. And when it is clicked second time, onclick() method is fired and notifyDataSetChanged() method is called. I tried to call the notifyDataSetChanged() method from the Focus Listener, list view selection is gone in my first attempt and edit text is not receiving any data input from the keyboard (frozen).Please help. Thanks, Venkat
Finally I fixed it. notifyDataSetChanged() on focus gained of edittext is recursively calling itself.Hence this issue was there. So, rather than calling notifyDataSetChanged() from focus listener I used a method in the activity to update the list from the focus listener of the edittext. Hence there was no issues of recursion with notifyDataSetChanged().