English 中文(简体)
在Clickable Widget获得点击事件的问题
原标题:Problem in geting click event in Clickable Widget

我写了一份可点击的植被。 我可以看到植被。 但是,我没有发现这种植被中的点击事件。 如果我点击植被,那么就应当采用收割方法。 但它没有被叫。 任何人都能够指导我可能是问题。

Source Code

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class MyWidget extends AppWidgetProvider {
    public static int IDs[];
    Context context;
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onReceive(context, intent);

        System.out.println("...inside receive11....");

        if (intent.getAction().equals("com.fedorvlasov.lazylist.NEXT_CLICK")) {
            System.out.println("Back Button Clicked ::::::::::::  ");

            onUpdate(context, AppWidgetManager.getInstance(context), IDs);
            // views = new RemoteViews(context.getPackageName(), R.layout.main);
        }
        if (intent.getAction().equals(
                "com.fedorvlasov.lazylist.NEXT_CLICK_NEXT")) {
            System.out.println("Onion Button Clicked Button:::::::::::: ");

            onUpdate(context, AppWidgetManager.getInstance(context), IDs);
            // views = new RemoteViews(context.getPackageName(), R.layout.main);
        }
        if (intent.getAction()
                .equals("com.fedorvlasov.lazylist.TEXTVIEW_CLICK")) {
            System.out.println("Next Button Clicked ::::::::::::  ");

            onUpdate(context, AppWidgetManager.getInstance(context), IDs);
        }
        System.out.println("...out to receive11....");

    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        // TODO Auto-generated method stub
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        IDs = appWidgetIds;
        this.context = context;
        System.out.println("...inside update....");
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.mywidget);

        Intent buttonPrevious = new Intent(context, MyWidget.class);
        buttonPrevious.setAction("com.fedorvlasov.lazylist.NEXT_CLICK");
        PendingIntent pendingIntentButtonP = PendingIntent.getBroadcast(
                context, 0, buttonPrevious, 0);
        remoteViews.setOnClickPendingIntent(R.id.mywidget_left,
                pendingIntentButtonP);

        Intent buttonMiddle = new Intent(context, MyWidget.class);
        buttonMiddle.setAction("com.fedorvlasov.lazylist.TEXTVIEW_CLICK");
        PendingIntent pendingIntentButtonM = PendingIntent.getBroadcast(
                context, 0, buttonMiddle, 0);
        remoteViews.setOnClickPendingIntent(R.id.mywidget_middle,
                pendingIntentButtonM);

        Intent buttonNext = new Intent(context, MyWidget.class);
        buttonNext.setAction("com.fedorvlasov.lazylist.NEXT_CLICK_NEXT");
        PendingIntent pendingIntentButtonN = PendingIntent.getBroadcast(
                context, 0, buttonNext, 0);
        remoteViews.setOnClickPendingIntent(R.id.mywidget_right,
                pendingIntentButtonN);


    }
}

In Manifest file

<receiver android:name=".MyWidget" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="com.fedorvlasov.lazylist.NEXT_CLICK" />
                <action android:name="com.fedorvlasov.lazylist.NEXT_CLICK_NEXT" />
                <action android:name="com.fedorvlasov.lazylist.TEXTVIEW_CLICK" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider"
                android:resource="@xml/widget_info" android:process=":remote" />
        </receiver>
最佳回答

你们不得不在最新方法中更新植被。

<>appWidgetManager.updateAppWidget(appWidgetIds,rangeViews); at the end of onUpdate() methods

问题回答

您必须把每一条带<代码>和t;action /> tag内附在<intent-filter /> tag in perperate.

这应当是一种ug,因为狗说,你可以在过滤器内采取不止一项行动:

Zero or more action [..] tags should be included inside to describe the contents of the filter.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签