Widget setOnClickPendingIntent not working

by Kasra Rahjerdi » Mon, 08 Mar 2010 12:20:20 GMT


Sponsored Links
 Hello,
I have a simple widget and I'm trying to pop up another activity when
it's clicked. My widget is not focusable or clickable even though in
the XML layout I explicity set it to be and when my widget is clicked
nothing happens.

My manifest has:
<receiver android:name=".WidgetConfigurator" android:label="@string/
app_name">
            <intent-filter>
                <action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget" />
        </receiver>

My layout is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
    android:id="@+id/widgetlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/widget_background"
    android:paddingLeft="19dip"
    android:paddingTop="21dip"
    android:clickable="true"
    android:focusable="true" >

        <TextView android:id="@+id/widgettext"
            android:text="Click here to set the text."
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_alignParentLeft="true"
            android:maxWidth="284dip"
            android:maxHeight="58dip"
            android:textSize="12dip"
            android:textColor="@android:color/black"
            />

</RelativeLayout>

And my AppWidgetProvider's onUpdate code contains:
        @Override
        public void onUpdate(Context ctx, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
                if(man == null)
                        onEnabled(ctx);

                Log.i(TAG, "Updating");
                RemoteViews updateViews = new RemoteViews(ctx.getPackageName(),
R.layout.widget);

                Random rand = new Random();
                for(int k = 0; k < appWidgetIds.length; k++) {
                int i = rand.nextInt(count);

                Intent intent = new Intent(ctx, WidgetClick.class);
                        PendingIntent pendingIntent = 
PendingIntent.getBroadcast(ctx, 0,
intent, 0);

                updateViews.setOnClickPendingIntent(R.id.widgetlayout,
pendingIntent);
                        updateViews.setTextViewText(R.id.widgettext,
storiesArray.get(i));

                        appWidgetManager.updateAppWidget(appWidgetIds, 
updateViews);
                }
        }


Everything in my onUpdate works perfectly other than the
setOnClickPendingIntent command. Am I doing something wrong?

--



Widget setOnClickPendingIntent not working

by String » Mon, 08 Mar 2010 19:07:48 GMT


 On Mar 8, 4:20am, Kasra Rahjerdi <johncena4presid...@gmail.com>




Try changing your PendingIntent.getBroadcast() call to a
getActivity(). If you're trying to start an activity, that would seem
to make more sense - and that's what works for my appwidgets.

String

--


Sponsored Links


Widget setOnClickPendingIntent not working

by Kasra Rahjerdi » Tue, 09 Mar 2010 02:22:00 GMT


 Good catch! Thank you. I've fixed this yet it has made no difference.
I can not even focus onto my widget and clicking it doesn't show any
highlight or anything either.





--



Widget setOnClickPendingIntent not working

by Kasra Rahjerdi » Thu, 11 Mar 2010 09:47:43 GMT


 I've made some progress. If I set my application up to do widget
updating in onRecieve everything works, similar code in the onUpdate
function does not.

--



Other Threads

1. RelativeLayout in ListView item

I've been experiencing some problems with the RelativeLayout when it
is used within a ListView item. I've created a simple example of the
problem below.

RelativeLayoutInListItemTest.java

public class RelativeLayoutInListItemTest extends ListActivity {
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                ArrayList<Map<String,String>> al = new
ArrayList<Map<String,String>>();
                al.add(new HashMap<String,String>());
                al.add(new HashMap<String,String>());
                al.add(new HashMap<String,String>());
                SimpleAdapter sa = new SimpleAdapter(this, al,
R.layout.relative_layout_in_list_item, new String[]{}, new int[]{});
                setListAdapter(sa);
        }
}

relative_layout_in_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
        >
        <TextView
            android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:text="Left Center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
        </TextView>
        <LinearLayout
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
                <TextView
                        android:text="Upper"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                </TextView>
                <TextView
                        android:text="Lower"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                </TextView>
        </LinearLayout>
</RelativeLayout>

Notice how only the lower half of "Left Center" is displayed. Also,
notice that "Upper" is not displayed.

Can someone confirm that this is a bug or point out my mistake?
--~--~---------~--~----~------------~-------~--~----~

2. opening H264 file in binary format

anybody can help me how to open h264 video file in binary format?

--~--~---------~--~----~------------~-------~--~----~

3. now that nothing interesting can be done with audio in 1.0...

4. Comming back to your application from a phone call

5. Irda support

6. Sensor values returned by tricorder

7. How can get the source code of the embedded app Pictures?