I am making an app which will have a simple home screen widget( A simple imageview ).
What i want is to call some specific function like abc() or xyz() whenever i click on this imageview widget on my homescreen.
I have gone through so many examples but did not find a single one which could teach me this and 90% of the example were using TextView which has a function setTextViewText so TextView one is simple but how to call some specific function when we click on imageview or how to set onClick for ImageButton.
Please help and i would really appreciate if you provide me some piece of code.
Thanks.
public class Sample extends Activity {
public static final String TAG = "Sample";
public void onCreate(Bundle saveInstanceState)
{
Log.e(TAG, "I am HERE");
Toast.makeText(this, "You Just Pressed Me", Toast.LENGTH_LONG).show();
}
}
HEre is my update method -
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
for(int i = 0; i < appWidgetIds.length; i++)
{
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, Sample.class);
//intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
//intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.hswidget);
views.setOnClickPendingIntent(R.id.widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}