Mehrere OnClick bei Widget für das selbe Intent

I

Inuyashaxp

Neues Mitglied
0
Und zwar hab ich ein Widget mit einem Service und der Service Updated 3 LinearLayouts.

Ich möchte auf jedes LinearLayout ein SetOnClickPendingIntent mit unterschiedlichen Extra setzen.

Aber wenn ich das Widget starte und auf eines der LinearLayouts klicke, dann ist nur das letzte anklickbar. Weiß jemand Rat? Danke.

Code:
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) {

                    }
        }

}
 
Selber auf die Lösung gekommen.

Musste den 3 PendingIntends unterschiedliche requestCodes zuweisen, sprich ich hab einfach Variable i genommen.

Grüße
 

Ähnliche Themen

Y
Antworten
4
Aufrufe
1.227
swa00
swa00
wernho
Antworten
11
Aufrufe
693
wernho
wernho
D
Antworten
17
Aufrufe
408
datNeMo
D
Zurück
Oben Unten