title: how to add setonclickListener to listview in android widgets
body: <p>i am creating simple application in android to show all products in widget. if i click on one item in list view, just open a activity or show a toast message in android.
  please help me i am new in android.</p>
  
  <pre><code>public class WidgetProvider extends AppWidgetProvider {
  
      /* 
       * this method is called every 30 mins as specified on widgetinfo.xml
       * this method is also called on every phone reboot
       */
      private static final String MyOnClick1 = "myOnClickTag1";
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
              int[] appWidgetIds) {
          final int N = appWidgetIds.length;
          /*int[] appWidgetIds holds ids of multiple instance of your widget
           * meaning you are placing more than one widgets on your homescreen*/
          for (int i = 0; i &lt; N; ++i) {
              RemoteViews remoteViews = updateWidgetListView(context,
                      appWidgetIds[i]);
              remoteViews.setOnClickPendingIntent(R.id.imageView, getPendingSelfIntent(context, MyOnClick1));
              //remoteViews.setOnClickPendingIntent(R.id.listViewWidget, getPendingSelfIntent(context, MyOnClick1));
              //remoteViews.setPendingIntentTemplate(R.id.listViewWidget, getPendingSelfIntent(context, "hai"));
              appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
          }
          super.onUpdate(context, appWidgetManager, appWidgetIds);
      }
  
      protected PendingIntent getPendingSelfIntent(Context context, String action) {
          Intent intent = new Intent(context, getClass());
          intent.setAction(action);
          return PendingIntent.getBroadcast(context, 0, intent, 0);
  
      }
  
      private RemoteViews updateWidgetListView(Context context, int appWidgetId) {
  
          //which layout to show on widget
          RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                  R.layout.widget_layout);
  
          //RemoteViews Service needed to provide adapter for ListView
          Intent svcIntent = new Intent(context, WidgetService.class);
          //passing app widget id to that RemoteViews Service
          svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
          //setting a unique Uri to the intent
          //don't know its purpose to me right now
          svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
          //setting adapter to listview of the widget
          remoteViews.setRemoteAdapter(appWidgetId, R.id.listViewWidget,
                  svcIntent);
          //setting an empty view in case of no data
          remoteViews.setEmptyView(R.id.listViewWidget, R.id.empty_view);
          remoteViews.setPendingIntentTemplate(R.id.listViewWidget, getPendingSelfIntent(context, "haiii"));
          return remoteViews;
      }
  
  
      @Override
      public void onReceive(Context context, Intent intent) {
          super.onReceive(context, intent);
          Toast.makeText(context, "Button1_out side", Toast.LENGTH_SHORT).show();
          if (MyOnClick1.equals(intent.getAction())) {
              // your onClick action is here
              Toast.makeText(context, "Button1", Toast.LENGTH_SHORT).show();
              Log.w("Widget", "Clicked button1");
  
  
          }
  
      };
  
  
  }
  </code></pre>