6

I am developing an android application.
I was created an activty that contains several components
on the top it contains spinner,

after that it contains linear layout in which it has two textview,
1 has static value and other is dynamic value that is filled when user click on that linear loyout an dialogbox is created and after setting value on that dialog it fills other textview.
i have 4 linearlayout of this type after that i have another linear layout at the end that contains 2 button.

The problem is that in emulator when i scroll mouse it focus on the spinner and after that the last button(means it color changes to orange)

So the question is that how can i get focus on that 4 linear layout?(i set focusable & focusontouch & clickable value true of that linearlayout.)

Anant
  • 109
  • 2
  • 5
  • 11

4 Answers4

5

I have done this, and setting android:clickable="true" on my LinearLayout did the trick. I just set a click handler for that layout when I set up my views.

Sky Kelsey
  • 19,192
  • 5
  • 36
  • 77
  • well i already set all 4 linear layout clickable="true" but it is not focusable even i did focusable true too, but its color is not changes as compare to other component like spinner(gets orange on focus) – Anant Sep 20 '11 at 05:18
  • 2
    In my `RelativeLayout` on API 23 (emulated), the minimum seems to be `android:focusableInTouchMode` and `android:clickable`. – David Lord Dec 25 '16 at 03:40
3

From @david-lord's comment, only the parameter

focusableInTouchMode="true"

is necessary, so in XML

<LinearLayout
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:focusableInTouchMode="true">

allows the call

linear_layout.requestFocus()
fireb86
  • 1,723
  • 21
  • 35
  • If you want to do this programmatically like inside a custom view you can use setFocusable(true); setFocusableInTouchMode(true); – mariozawa Jul 12 '19 at 03:01
1

I have a LinearLayout with:

      <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selectorbarbutton"
                android:clickable="true"
                android:focusable="true"
                android:orientation="vertical" >

and this work getting focus and click events correctly.

Zeus Monolitics
  • 832
  • 9
  • 19
1

Please try to set android:focusable=true ,

I am not sure about this but may solve your problem.

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
amity
  • 942
  • 1
  • 8
  • 24