11

私のウィジェットはサービスを開始し、サービスは3つのLinearLayoutのリストを更新します。

各LinearLayoutに異なるExtraを使用してSetOnClickPeningIntentを設定したい

しかし、ウィジェットを起動してLinearLayoutsをクリックしたい場合は、最後のウィジェットのみがonclickable=/何が問題なのかわかりません。あなたが私を助けてくれることを願っています。

RemoteViews remoteViews = new RemoteViews(getPackageName(),
        R.layout.widget_layout);


for (int widgetId : appWidgetIds) {


    int[] lls = { R.id.ll_con_1, R.id.ll_con_2, R.id.ll_con_3 };


        for (int i = 0; i < jray.length(); i++) {

                    try {

                        JSONObject o = jray.getJSONObject(i);

                        //Onclick
                            if(i == 0)
                            {
                                Intent msg_intent = new Intent(getApplicationContext(), MSGsOpenMsg.class);
                                msg_intent.putExtra("messageid", o.getString("id"));
                                PendingIntent msg_pendingIntent = PendingIntent.getActivity(
                                        getApplicationContext(), 0, msg_intent, Intent.FLAG_ACTIVITY_NEW_TASK);
                                remoteViews.setOnClickPendingIntent(R.id.ll_con_1, msg_pendingIntent);
                            }
                            else if(i == 1)
                            {           
                                Intent msg_intent1 = new Intent(getApplicationContext(), MSGsOpenMsg.class);
                                msg_intent1.putExtra("messageid", o.getString("id"));
                                PendingIntent msg1_pendingIntent = PendingIntent.getActivity(
                                        getApplicationContext(), 0, msg_intent1, Intent.FLAG_ACTIVITY_NEW_TASK);
                                remoteViews.setOnClickPendingIntent(R.id.ll_con_2, msg1_pendingIntent);
                            }
                            else if(i == 2)
                            {
                                Intent msg_intent = new Intent(getApplicationContext(), MSGsOpenMsg.class);
                                msg_intent.putExtra("messageid", o.getString("id"));
                                PendingIntent msg2_pendingIntent = PendingIntent.getActivity(
                                        getApplicationContext(), 0, msg_intent, Intent.FLAG_ACTIVITY_NEW_TASK);
                                remoteViews.setOnClickPendingIntent(R.id.ll_con_3, msg2_pendingIntent);
                            }

                    } catch (JSONException e) {

                    }
        }

}
4

1 に答える 1

22

私はこの問題を抱えています。これは、Androidが同様のPendingIntentsを1つにまとめようとするためであり、これは非常に厄介な結果をもたらします。IEの古いインテントは、微妙に異なる場合は削除されます。ドキュメントと一致しないため、折りたたむ方法にもバグがあると思います。(私はずっと前にこれに遭遇したので、状況が変わった可能性があります。)

基本的に、 PendingIntent.getActivityのrequestCodeパラメーターがUIアイテムごとに異なることを確認します。そうすれば、それぞれが独自のPendingIntentを取得し、衝突することはありません。

私はここに問題を回避しようとするコードを持っていますが、それは少し無駄です。 http://code.google.com/p/futonic-mylocationwidget/source/browse/src/com/futonredemption/mylocation/Intents.java#35

私のコードの解決策は最善ではないことを認めますが、これまでのところかなりうまく機能しているようです。

于 2011-07-31T19:54:13.180 に答える