I have a GridView to which a custom adapter is set. getView() method of the custom adapter returns a LinearLayout with two TextView and an EditText arranged horizontally. I have made a custom numeric keyboard for entering text in the EditText. Keyboard contains NEXT and PREV buttons as well which are creating problems. I want NEXT button to automatically focus the next EditText in the next row and similarly PREV button. NEXT button onKeyPress seems like:
View v=getWindow().getCurrentFocus().focusSearch(View.FOCUS_FORWARD);
if(v!=null)
v.requestFocus();
The code seems right. The problem is, suppose currently only three rows are visible of gridView,if the focus is on the third EditText and NEXT is pressed,it then focuses on nothing. I dont know how to solve this issue. If anyone knows how to solve it.
Thanx in advance.
Can you maintain a collection of ids of all the editText's in the same order, while adding them for rendering.
In that case, for clickHandler or NEXT/PREV button, u can check following:
clickHandler of PREV: if present selection is first in list, then you might want to set focus on last element in list.
clickHandler of NEXT: if present selection is last in list, then you might want to set focus on first element in list.
Alternatively, if you do not want a list roll back functionality, you can just check the position of element in list, and handle the brink elements any way u want them to be.
Hope I understood your problem correctly.
HTH
Related
My row in list that has editText in it, beside other things. If I set android:focusableInTouchMode="false" on editText, I am able to select my entire row, highlight it, get data I need, but I no longer can edit my editText, because keyboard doesn't pop up. If I set android:focusableInTouchMode="true", then I can edit editText, but i can't click on entire row, highlight it, get data. How can I achieve both?
ListView isn't adapted for inputs. It keeps in memory only visible items + 2. So even if you will achieve the that what you want, all your edits will dessapear after every time, your EditText leaves the screen.
Take a look at RecyclerView view documentation. This class is better adapted to this kind of stuff.
UPD
Actually, there is a tutorial exactly for foucsable EditTexts in ListView. But as you see, it was relevant for 2011.
It's easy to make a row in a ListView do something when it is clicked. But add something else in the row--such as a Button or other control--that has an OnClickListener, and suddenly nothing happens when the row is clicked.
Before you close this question as a duplicate, I am perfectly aware that there are a number of StackOverflow questions about that. They generally either recommend setting the Button android:focusable="false" or setting android:descendantFocusability="blocksDescendants" on the ViewGroup containing the row Views.
These work, but one problem: if you're navigating with the keyboard (tabbing or arrow keys), it skips right over the Button.
Is there a way to solve the issue and allow people to "click" either row or Button without having to actually tap the touchscreen?
Setting an OnClickListener on each row (instead of setting an item click listener for the ListView) did not help.
I did find some more info, such as using ListView.setItemsCanFocus(true) Using Android, how can I select rows from a ListView which contains Button controls and using beforeDescendants Focusable EditText inside ListView but can't get both the row and the button to be usable with a keyboard.
BUT it occurred to me to try and test out Gmail with a keyboard. I can't find a way to mark a row as a favorite (select the star). So apparently even they aren't making it fully accessible! Oh well. A lose cause I suppose.
Need to implement edit in runtime. Which one is the best way to achieve it.
Edittext in Listview or dynamic table layout(inflating row xml) with edittext
Update:
My listview contains 7-8 view(Text view) in a list item. On click edit button using view switcher changed textviews to edit text. To get the entered value in edittext listening onfocuschanged. It brings very slow performance. Any better way to achieve it?
Update:
If my listview have 100 list items. Each item having 7-8 edittext. Need to listen all the edittext focuschange. My app hangs. What should i do?
EditText within ListView can cause you great grief down the lane given that views are recycled in listview.
Say you have tapped on the second row in a listview where all item rows contain a edittext and you have set adjustResize in your AndroidManifest.xml; after the soft keyboard pops up, the focus goes into the first view that can accept the focus which in this case will be the first edittext (row) of your listview. Yes, you can tap again on the desired edittext to regain focus. But it is an annoyance nevertheless. If you set adjustPan, then I have seen the the problem does not exist as such; if I recollect correctly, you cannot scroll down all the way to the end of your list. Again, another annoyance.
I'd suggest, you go with a ScrollView if the number of items in the list are less. I have been trying to solve this for the last couple of days - I ended up doing this - I replaced the edittext's with textview's in the listview; tapping on the textview would bring up a dialog fragment that contains the edittext.
Have you looked into the concept of a ViewHolder to keep a reference to the items of the listview? That should solve your multiple focus listener problems.
I have a custom list row which has two TextView and one EditText .
I want to clear the text typed in EditText of all the list rows on a Button click which is a reset button.
The Button is in an Activity
Can anyone suggest me a way I can achieve this.
Well your question is not clear at first, if you mean a system like listview or scroller when you say custom list row, then while on click of button do the following
Get all the child from the view
loop through each child, finding EditText inside each child view
Simply setText to empty.
I hope got your question right, else please put some code here.
You can use this to clear the editText
YourEditText.setText("");
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