tags:

views:

149

answers:

2

I have a widget that acts as a launcher on the home screen. How can I make it behave like a launcher icon?

I use this layout for portrait:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <RelativeLayout
    android:background="@drawable/widget_background_selector"
    android:focusable="true"
    android:layout_width="74dip"
    android:layout_height="79dip"
    android:layout_marginLeft="3dip"
    android:layout_marginTop="14dip">

    <ImageView android:id="@android:id/background"
      android:layout_width="72dip"
      android:layout_height="72dip"
      android:layout_marginLeft="1dip"
      android:layout_marginTop="4dip" />

  </RelativeLayout>

</RelativeLayout>

And this is the background selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
  <item android:state_pressed="true" android:drawable="@drawable/widget_background_pressed" /> 
  <item android:state_window_focused="true" android:state_focused="true" android:drawable="@drawable/widget_background_focused" /> 
  <item android:state_window_focused="false" android:state_focused="true" android:drawable="@android:color/transparent" /> 
</selector>

This way if I use the DPAD the widget is focusable but the click doesn't work. The touch still works but the widget is not displayed as focused.

Any idea what I do wrong?

A: 

Just a shot in the dark, but have you tried setting android:focusableInTouchMode to true?

Roman Nurik
I tried that too ... but nothing changed
Tughi
A: 

What about the code that registers your click events? Can you show that?

I don't see any id attribute for your RelativeLayout, so my stab is that you haven't even registered an OnClickPendingIntent for the RelativeLayout for which you want to handle click events. And perhaps you have created an intent for the ImageView, which is receiving the touch events, but not the dpad click events, because it's parent (the RelativeLayout) has requested focus (and has no click event-handler).

Scott Main
I found what was the problem a week ago, but I forgot to close this question.It was related to the missing ID as you noticed. :-)
Tughi