package pack.GestureSampleThree;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import android.widget.LinearLayout;
import android.widget.TextView;
public class GestureSampleThreeExample extends Activity implements OnGestureListener {
private LinearLayout main;
private TextView viewA;
private GestureDetector gestureScanner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gestureScanner = new GestureDetector(this);
main = new LinearLayout(this);
main.setBackgroundColor(Color.GRAY);
main.setLayoutParams(new LinearLayout.LayoutParams(320,480));
viewA = new TextView(this);
viewA.setBackgroundColor(Color.YELLOW);
viewA.setTextColor(Color.BLACK);
viewA.setTextSize(16);
viewA.setLayoutParams(new LinearLayout.LayoutParams(320,80));
main.addView(viewA);
setContentView(main);
}
@Override
public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);
}
public boolean onDown(MotionEvent e) {
viewA.setText("-" + "DOWN" + "-");
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
viewA.setText("-" + "FLING" + "-");
return true;
}
public void onLongPress(MotionEvent e) {
viewA.setText("-" + "LONG PRESS" + "-");
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
viewA.setText("-" + "SCROLL" + "-");
return true;
}
public void onShowPress(MotionEvent e) {
viewA.setText("-" + "SHOW PRESS" + "-");
}
public boolean onSingleTapUp(MotionEvent e) {
viewA.setText("-" + "SINGLE TAP UP" + "-");
return true;
}
}
On Thu, Sep 8, 2011 at 12:02 AM, rich friedel <rich.friedel@gmail.com> wrote:
If that is the way you are doing it then I would (as others have) recommend reading up on how to listen and respond to click events. I see absolutely no reason to use an if/else statement when the listener is tied directly to the button.See nrmally when we have a button in a page in the onClick(View v ){
if(btn1==v)
{
startActivity(new
Intent(FirstScreenActivity.this,SecondScreenActivity.class));
}
}Also you can make the ENTIRE view clickable: http://developer.android.com/reference/android/view/View.OnClickListener.html--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment