1

I'm creating a widget that had a button! When I click on a button. It just reads my location and toasts it! It should not open any activity! Just a toast on the button click in the widget! Need help!

1 Answer 1

2

You need to call

Toast.makeText(context, "Hi there!", Toast.LENGTH_LONG).show();

in widget's onClick() method of View.OnClickListener

If using AppWidgetProvider take a look at this and this

Sign up to request clarification or add additional context in comments.

2 Comments

For widget it extends from Appwidgetprovider!, Does the findviewbyId work in widget class?? I tried XML attribute android:onClick also, but couldn't make it work,, where as the toast is working fine in onUpdate, onEnabled and onDisabled methods
I did refer! I'm positive for invoking an activity on image button press! But I need a toast! I invoke a toast on a image button click!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.