ImageButton focus algorithm problem.

Put your problem here if it does not fit any of the other categories.

ImageButton focus algorithm problem.

Postby x-files » Thu Feb 28, 2008 1:11 pm

First screen:

This screen contains button. When we click it we go to second screen.

Second screen:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.        android:orientation="horizontal"
  4.  
  5.        android:layout_width="fill_parent"
  6.  
  7.        android:layout_height="fill_parent">
  8.  
  9.         <ImageButton
  10.  
  11.                 android:id="@+id/button_1"
  12.  
  13.                 android:focusableInTouchMode="true"
  14.  
  15.                 android:layout_width="wrap_content"
  16.  
  17.                 android:layout_height="wrap_content"
  18.  
  19.                 android:src="@drawable/calc_0_f"/>
  20.  
  21.          <ImageButton android:id="@+id/button_2" ... />
  22.  
  23.          <ImageButton android:id="@+id/button_3" ... />
  24.  
  25.          <ImageButton android:id="@+id/button_4" ... />
  26.  
  27. </LinearLayout >
  28.  
  29.  
  30.  
  31.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


onCreate#
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. findViewById(R.id.button_3).requestFocus();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



When I click the left button then the focus moves to R.id.button_1 but it should be moved to R.id.button_2.

PS: when i launch second screen directly the focus work as expected.

Thanks in advance!
Attachments
ImageButtonInv.zip
(37 KiB) Downloaded 87 times
x-files
Developer
Developer
 
Posts: 44
Joined: Fri Jan 11, 2008 10:27 am

Top

focus bug?

Postby cybohemia » Wed Mar 05, 2008 8:58 am

There does appear to be a bug - or buggish thing, anyway - with the focus. I have a similar situation where I want a button to be the default focus. It works well enough if the user doesn't click on anything else in the page. But if something else gets an interaction, the focus goes to an unexpected element - in my case, an edit box above the checkbox and the button.

I've attached a very simplified version of the problem for clarity (it does the same thing with more elements on the page).

If you want to give it a go, here's the run through:

Goal: To allow the user to switch back and forth between the screens by just pressing the center key on the directional keypad.

Problem: Things do not revert back after the user modifies the screen.

Steps:
1. Start the app
2. Click on the center key [see 2nd screen]
3. Click on the center key [return to original screen]
4. Click on the center key [see 2nd screen again - note button is still default, as desired]
5. Click on the center key [return to original screen]
6. Click on the center key [see 2nd screen]

-- everything is fine so far... --

7. Click on the check box [focus jumps to edit text box...? This is unexpected]

-- with other elements in various parts of the screen, it was still jumping here --

8. Click on the center key [nothing happens]

-- well, the previous step caused the edit text to gain the focus so... --

9. Click on the button explicitly (i.e. use the screen) [return to original screen]

-- now, we are back to where we started...or, so we would like to be but... --

10. Click on the center key [see 2nd screen - but the button is no longer the default!]

-- we want the button to be the default but the edit text box is now the default --

I've tried the requestFocus() call and it returns TRUE but the button is not getting the focus.

I'm thinking of logging this onto the google bug tracking system but am posting it here first, as suggested by this forum.

Any thoughts would be greatly appreciated - thanks!
Attachments
focusbug.zip
Small test of apparent focus bug in Android m5-rc14
(35.46 KiB) Downloaded 80 times
cybohemia
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sun Mar 02, 2008 12:21 am

Postby plusminus » Wed Mar 05, 2008 9:44 am

Hello cybohemia

I gave it a try. And yes it seems to be a small bug (or two).

Note: The focus cannot be changed using touch/clicks!

Strange is that the EditText receives the focus after clicking the CheckBox. As I said, touch usually doesn't change the focus, but perhaps if there was no focus before the focus jumps to the uppermost view?

Is it always the EditText or the uppermost View the focus jumps to ?

I think it is valuable of submitting.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

focus bug

Postby cybohemia » Wed Mar 05, 2008 10:59 am

Hi, plusminus.

Thanks for checking out the issue.

>> Note: The focus cannot be changed using touch/clicks!

Regarding how "the focus cannot be changed using touch/clicks!" maybe I'm using the wrong terms? When I touch an EditText box, it is highlighted and then, if I start typing things, the keys I type are routed there. I see that as the EditText box having gained focus as a result of a touch. Maybe there's another way to say that(?) but...by the way, why shouldn't touch or clicks change focus?

>> Strange is that the EditText receives the focus after clicking the CheckBox. As I said, touch usually doesn't
>> change the focus, but perhaps if there was no focus before the focus jumps to the uppermost view?

I had a requestFocus() call made from the button and so, when the screen first shows, that button is highlighted (as expected) and responds to the center key on the directional keypad. So there is an initial focus on the button. When the user clicks on the checkbox, my interpretation is that it puts the focus on the checkbox. If it doesn't, then the checkbox shouldn't be highlighted. If it does, then it should be. Either way, having the focus jump to an element above it seems strange.

>> Is it always the EditText or the uppermost View the focus jumps to ?

It seems to always jump to the first EditText box - even if there are elements above it (like radio buttons). In fact, if an EditText box 1 is declared in the XML file before an EditText box 2 but has a layout_below="EditText2" attribute to place it below EditText box 2 on the screen, it shows up above it anyway(!) and then the focus jumps to it (EditText box 1). I'm not sure if that is a related issue (the google docs does mention that things tend to show up in the order they are declared in the XML file but I just thought the layout_below attribute would do something...) or if I am just fiddling around with the attributes too much...

I'll post this to google.

Thanks!

cybohemia
cybohemia
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sun Mar 02, 2008 12:21 am

Postby plusminus » Wed Mar 05, 2008 11:48 am

Hello cybohemia,

Android differs between selection and focus! (I'm also nto 100% sure 'what is what')
So you can have your cursor in an EditText, then check a Checkbox without loosing the selection[sup](?)[/sup] to the EditText.

The otherway around: EditText seems to be on of the minor Widgets that also get selected[sup](?)[/sup] when being touched.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests