Android GridView focus order - android

Help me, please! How can I set an order to changing focus in gridview with edittexts?
Now it looks like this:
(1)(2)(3)
(4)(5)(6)
(7)(8)(9)
When I press "Next" on keyboard, focus move 1-4-7 finish 2-5-8 finish 3-6-9. I need 1-2-3-4-5-6-7-8-9... items adding dynamically.

Get an instance of your EditText in the code, then call edittext1.setNextFocusDownId(R.id.edittext2); and hence do this for all youre EditText.

Related

Kotlin recyclerView nextFocusDown

I need to make nextFocusDown on items in recyclerView. Every item has the same id, but to make nextFocusDown I need to have specific id. How shoudl I do this in recycerView to make focus on next edittext in list?
You can put focus on your edit text programmatically. Get the event when the user presses enter button or some button that tells you the user is done editing the first edit text. Then you can programmatically put focus on next item in recyclerview using following code:
edittext.setFocusableInTouchMode(true);
edittext.requestFocus();

TextBox loses focus in listview when first character is typed

I am stuck with a strange problem for quite a while now. I am using listview to populate my screen. When I type anything in any text box it loses focus when the first element is typed. If I click on the textbox again then everything goes fine and I can type continuously. From the logs I can see that when the first element is typed in any EditText getView() gets called. Once I select the text field again then beforeTextChanged-onTextChanged-afterTextChanged are called continuously which is correct. Can someone help out please. I have tried solutions like making list view height to "fill_parent" and adding android:windowSoftInputMode="adjustPan" to my manifest.xml. Nothing works.
Thanks in advance!
I found the solution. getView() gets invoked internally whenever the screen dimensions are to be ascertained. In my case I had a hidden textview above the editText box. Whenever I was typing something in the editText box I was changing the visibility of the textView from GONE to VISIBLE. That is why the screen placement was changing and so getView() was getting invoked, resulting in the focus being lost. I changed the hidden textView from GONE to INVISIBLE. This way it kept its place in the display and hence even when it became VISIBLE, getView() didnt get invoked.

Android GridView Focus Issueon children?

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

android where to put code that will execute when ListView is done displaying?

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.

get a small list when clicked on a button

i have a image view and on top of it i have a button. now what i want is when i click on the button i should get a list of images on same Activity.actually i am trying to make a list in button,s onClick event. event gets fired but it does not show the list. anybody can have any idea how shall i achieve this i am also making my layout programmatically.
thanks alot
Without seeing some code it's hard to give a definite answer, but these are a few possibilities.
Create the listview together with the button, but set it's visibility to View.GONE or View.INVISIBLE. In the button's onClick method, set it to View.VISIBLE.
Alternatively, do the listview creation in the button's onClick (which I gather is what you're doing?), making sure you don't forget to add it to your layout. I have no idea why this does not work for you. Show some code or use the debugger to step through it and find out where it goes wrong.

Categories

Resources