开发者

Not responce click on widget

开发者 https://www.devze.com 2023-03-15 17:50 出处:网络
I hav开发者_开发问答e different controls on a widget (TextView, ImageView...). On some controls I set setOnClickPendingIntent (for example - tvInfo). It work. On click on TextView I get onReceive my w

I hav开发者_开发问答e different controls on a widget (TextView, ImageView...). On some controls I set setOnClickPendingIntent (for example - tvInfo). It work. On click on TextView I get onReceive my widget.

protected final void addClickListener(String action, int layoutId) {
    Log.d(TAG, "addClickListener " + action);
    Intent intent = new Intent(WidgetInfo.Context, getMainWidget());
    intent.setAction(action);
    PendingIntent actionPendingIntent =
        PendingIntent.getBroadcast(WidgetInfo.Context, 0, intent, 0);
    remoteViews.setOnClickPendingIntent(layoutId, actionPendingIntent);

But if I click on another part of widget (where not set setOnClickPendingIntent) and then again on tvInfo. Nothing happens and onReceive not response. If I repeatedly click on tvIfo then onReceive work. Also, If I double click or even number of times and then again on tvInfo, onReceive response. onReceive not response only if I click on empty part of widget odd number of times.


I solved the problem as follows:

  • add setOnClickPendingIntent for top linearLayout of widget;
  • set android:soundEffectsEnabled="false" for this linearLayout.
0

精彩评论

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