Search code examples
androidandroid-appwidgettouch-eventontouchlistener

Detect OnTouch on AppWidget. If is it possible?


Detect OnTouch on AppWidget. If is it possible? Hello! I'm trying to create my first AppWidget for Android 2.1 in which a client may have a chance to select an item on my custom view. I'm going to create a custom view and a slider for it and client may select by pulling slider over the custom view. For this purpose I want to detect onTouch for AppWidget (to determine X-, Y- coordinates), is there way to do this?

I saw a list of valid widgets which can be used in AppWidget:

  • AnalogClock
  • Button
  • Chronometer
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView
  • ViewFlipper
  • ListView
  • GridView
  • StackView
  • AdapterViewFlipper

However they do not fit my needs. I have Googled this but find nothing which could help me. IS there any way to detect OnTouch within an AppWidget? Perhaps this would require me to have a newer API version.


Solution

  • It seems that there is no way to detect touch on AppWidget.RemoteViews have no method to detect it(we can not register a touch listener for them).

    Mark Murphy(CommonsWare) in detect onTouch for widget says:

    You don't detect "on touch" for app widgets. You can, however, detect clicks, via setOnClickPendingIntent() on RemoteViews. AFAIK, this works for all View classes supported by RemoteViews.

    Also,you can not use StackView in AppWidgets in Android2.1 (see simulate stack view in Android2(API 5)?).