开发者

How Linear Layout get Focus?

I am developing an android application.

I was created an activty that contains sev开发者_开发问答eral 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.)


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.


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()


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.


Please try to set android:focusable=true ,

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜