开发者

Touchlistener on widget ?

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[]  appWidgetIds) {        
    for (int appWidgetId : appWidgetIds) {
       int imageNum = (new java.util.Random().nextInt(IMAGES.length));
       RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.main);
       remoteView.setImageViewResource(R.id.image, IMAGES[imageNum]);
       appWidgetManager开发者_C百科.updateAppWidget(appWidgetId, remoteView);
    }
}

I want use touchListener here on widget so I can change photos. What I should I call or write for that?


Use the function setonClickPendingIntent on remoteView and provide the id of image/button. so that the pending intent will be launched when you click that button.

For example:

PendingIntent pintent = PendingIntent.getBroadcast(/*Input Arguments*/);
remoteView.setonClickPendingIntent(R.id.image,pintent);

Now as we use PendingIntent.getBroadcast to create our pending intent, when it will be launched it will be same like SendBroadcast so we have to implement a onReceive now.

Now Simply put your on Click Logic in onReceive.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜