Widgets, can they register a Press or Release event?

Put your problem here if it does not fit any of the other categories.

Widgets, can they register a Press or Release event?

Postby pcm2a » Sat Oct 17, 2009 12:45 am

I have used the onClick even with many buttons on widgets to know when my button was pressed. However, what I would like to do is know when the finger is down and when it is back up. Is this possible with a widget?

Thanks!
pcm2a
Developer
Developer
 
Posts: 27
Joined: Tue Aug 11, 2009 4:54 pm

Top

Postby qlimax » Tue Oct 20, 2009 2:08 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.ontouch;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.MotionEvent;
  10.  
  11. import android.view.View;
  12.  
  13. import android.view.View.OnTouchListener;
  14.  
  15. import android.widget.Button;
  16.  
  17. import android.widget.TextView;
  18.  
  19.  
  20.  
  21. public class OnTouch extends Activity {
  22.  
  23.     /** Called when the activity is first created. */
  24.  
  25.     @Override
  26.  
  27.     public void onCreate(Bundle savedInstanceState) {
  28.  
  29.         super.onCreate(savedInstanceState);
  30.  
  31.         setContentView(R.layout.main);
  32.  
  33.         final TextView tw=(TextView)this.findViewById(R.id.tw);
  34.  
  35.         Button b=(Button)this.findViewById(R.id.Button01);
  36.  
  37.        
  38.  
  39.         b.setOnTouchListener(new OnTouchListener() {
  40.  
  41.                        
  42.  
  43.                         @Override
  44.  
  45.                         public boolean onTouch(View v, MotionEvent event) {
  46.  
  47.                                 // TODO Auto-generated method stub
  48.  
  49.                                
  50.  
  51.                                 if(event.getAction()==MotionEvent.ACTION_DOWN){
  52.  
  53.                                         tw.setText("pressed");
  54.  
  55.                                 }else if (event.getAction()==MotionEvent.ACTION_UP) {
  56.  
  57.                                         tw.setText("released");
  58.  
  59.                                 }
  60.  
  61.                                
  62.  
  63.                                 return true;
  64.  
  65.                         }
  66.  
  67.                 });
  68.  
  69.     }
  70.  
  71. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



;) I hope that's what you mean

:run:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby pcm2a » Tue Nov 03, 2009 4:17 am

Unfortunately there is no "findViewById" when you extend AppWidgetProvider, since this is a widget. There is also no findViewById in RemoteViews.
pcm2a
Developer
Developer
 
Posts: 27
Joined: Tue Aug 11, 2009 4:54 pm

Postby qlimax » Tue Nov 03, 2009 11:21 am

sorry, i didnt understand that you meant handling buttons on homescreen widget...
I don't know how to handle press/release events on that buttons (maybe it's not possible :? )...
for the classic click I think you already found a solution here viewtopic.php?p=27904 right ?
bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests