2011-06-26 57 views
0

我對窗口部件(TextView,ImageView ...)有不同的控制。在一些控件上,我設置了setOnClickPendingIntent(例如 - tvInfo)。這行得通。點擊TextView,我可以獲取onReceive我的小部件。沒有響應點擊小部件

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); 

但如果我點擊窗口小部件的另一部分再次tvInfo(其中沒有設置setOnClickPendingIntent),然後。沒有任何反應,onReceive沒有反應。如果我反覆點擊tvIfo然後onReceive工作。此外,如果我雙擊或甚至次數,然後再次在tvInfo,onReceive響應。 onReceive只有當我點擊widget的空白部分奇數次時纔回應。

回答

1

我解決了這個問題,如下所示:

  • 對widget的頂部的LinearLayout加setOnClickPendingIntent;
  • 爲此linearLayout設置android:soundEffectsEnabled =「false」。