开发者

Weird onclick behavior of images on home screen widget

开发者 https://www.devze.com 2022-12-26 05:30 出处:网络
I wrote a home screen widget with one image on it. When the image is clicked, browser will be opened for a url link.

I wrote a home screen widget with one image on it. When the image is clicked, browser will be opened for a url link. Generally, it is working. But a weird thing is that, when I click background, then click the picture, the browser will not be open. Until I click the second time on the pict开发者_StackOverflow社区ure, the browser opens. The steps to reproduce is below:

  1. Click on the home screen widget background.
  2. Click on the image on the home screen. The browser is not opened.
  3. Click on the image again. The browser is opened.

If I didn't click on the background, the image will react to click very well, i.e. browser will be open when the image is clicked the first time.

The widget XML file is as below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="320dip" android:layout_height="200dip"
    android:background="@drawable/prt_base"
>
    <ImageView android:id="@+id/picture1"
        android:layout_width="134dip"
        android:layout_height="102dip"
        android:layout_marginLeft="62dip"
        android:layout_marginTop="6dip"
        android:scaleType="center"
                android:src="@drawable/picture1"
    />
</RelativeLayout>

The code to set OnClick on the picture1 ImageView is as below:

                        defineIntent = new Intent(Intent.ACTION_VIEW, Uri
                                .parse("http://www.google.com"));
                        pendingIntent = PendingIntent
                                .getActivity(context,
                                        0 /* no requestCode */,
                                        defineIntent, 0 /* no flags */);
                        updateViews.setOnClickPendingIntent(
                                picId, pendingIntent);

Anyone knows what's wrong?

Thanks.


  RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.mywidget);

    Intent defineIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
        PendingIntent pendingIntent = PendingIntent.getActivity(context,
                0 , defineIntent, 0 );
   updateViews.setOnClickPendingIntent(picId, pendingIntent);

   appWidgetManager.updateAppWidget(appWidgetId, updateViews );

it will work!

could you post your appwidget-provider ???

0

精彩评论

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