How do I add a button to a widget, not for opening an activity or something?
Just for toggling for example Wi-Fi 🙂 Could it be done by a ImageButton or something like that? I just can’t figure out how to add an onClickListener.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I have updated my answer now that I understand you are trying to write an AppWidget.
AppWidgets support only a limited set of Views and ToggleButton is not one of them. The list of Views supported by AppWidgets can be found here:
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
You will have to use an ImageButton and remember its toggled state yourself. You can set it’s image source to a different image depending on whether it is toggled or not. See ImageButton for more info:
http://developer.android.com/reference/android/widget/ImageButton.html