0

I have a widget with 3 pictures. Each picture describe a different things.

I have a class with just a webviewer inside. I want that if the user touch the first picture, the webviewer is launched to the address 1, 2 if it's the second picture, etc.

    Intent i = new Intent(context, WebViewTestActivity.class);
    i.putExtra("url", "http://www.google.com");
    PendingIntent pi = PendingIntent.getActivity(context,0, i,0);
    views.setOnClickPendingIntent(R.id.img1, pi);

The problem is in the class with the webviewer, i take the url from the extra value of the intent. But how can i add three url with the same "key" (url) and how i can know that the user click on the first image, the second image etc... on the webviewer class ?

Thanks.

EDIT :

I found the solution here :

Processing more than one button click at Android Widget

use i.setAction("url1...."); (with i your intent)

Thanks

Community
  • 1
  • 1
Dahevos
  • 1,495
  • 5
  • 16
  • 26
  • You need to be more specific. If you only view one url in the webview (one at a time), then why do you need three of them? If you need all free, why don't you just pass them in "url1", "url2", "url3". Even if only one is needed you can always send also `i.pusExtra("selectedUrl", 1)` or something – Michał Klimczak Jun 20 '12 at 14:04
  • What i mean is i need in fact to "call" the activity with an url in parameter. I have 3 differents images with 3 differents url. Now the problem is in the webview i can't know on which image the user click, so i can't know which url to display. My question is more about "how to have a kind of "dynamic" intent where depend on which image the user click, the content of the intent is different. Thx – Dahevos Jun 20 '12 at 14:11
  • Just create the Intent in `onClickListener`, that's all:) – Michał Klimczak Jun 20 '12 at 14:39
  • Thanks michal K for your answer. The problem is I used widget, so i don't have onCLickListener in the normal way. I need like my code sample to use setOnClickPendingIntent, so how can i specify the intent in this "listener" ? Thanks – Dahevos Jun 20 '12 at 14:44
  • And is there a problem to `setOnClickPendingIntent` separately on each view containing image? I'm not experienced in `RemoteView`s, that's why I'm asking, but it seems reasonable to do it this way. There 's also http://developer.android.com/reference/android/widget/RemoteViews.html#setPendingIntentTemplate(int, android.app.PendingIntent) which is used to set pedning intents on collection views. – Michał Klimczak Jun 20 '12 at 16:41
  • i found the solution, i edit my message. Thanks Michal K for your support. – Dahevos Jun 21 '12 at 14:53

1 Answers1

0

I found the solution here :

Processing more than one button click at Android Widget

use:

i.setAction("url1...."); // (with i your intent)
blackgreen
  • 34,072
  • 23
  • 111
  • 129
Dahevos
  • 1,495
  • 5
  • 16
  • 26