开发者

ListView addHeader() - all child views becoming focused when tapping anywhere in header?

I have a ListView. I want to add a header view, which has two focusable controls:

<LinearLayout
  android:layout_width="fill_parent"
  android:layout_width="wrap_content">

  <LinearLayout
    android:background="@drawable/selector_foo"
    />

  <LinearLayout
    android:background="@drawable/selector_grok"
    />

</LinearLayout>

So I see both my child layouts in the header view, and the strange thing is, tapping anywhere in the header area (even if I miss 开发者_开发知识库either child) results in both of them being "selected", as I can see their background resource change.

Both selector_foo and selector_grok have a different background image to display when the selected / focused state = true.

I'm wondering if there's a way to stop this behavior? I put click handlers on both of the children, and they are correctly only firing when I intersect them. Not sure why their selected state is becoming true if I tap anywhere in the header though.

Thanks


Ok so turns out I was adding it like so:

listView.addHeaderView(view, null, true);

the last parameter being "isSelectable". Since my inner controls can focus, I don't need the whole item to be selectable, so changing it to false makes it behave properly.


listView.addHeaderView(view, null, false);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜