I have a set of java code which i try to detect touch gestures by users. When a user do a simple touch/swipe down etc, a text view will display out what the user has currently done. However when i run the code on my emulator, it is just a black screen which show Hello World! and when i do a touch, nothing is display.. why is that so? Attached is the code. Thanks for your help...
package org.tp.iit.cds.BrailleTypeSend;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector;
import android.widget.TextView;
import android.graphics.Color;
public class BrailleSend extends Activity implements OnGestureListener {
/** Called when the activity is first created. */
public LinearLayout main;
public TextView viewA;
public 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.WHITE);
viewA.setTextSize(16);
viewA.setLayoutParams(new LinearLayout.LayoutParams(320,80));
main.addView(viewA);
setContentView(R.layout.main);
}
@Override
public boolean onDown(MotionEvent e) {
viewA.setText("Down Stroke");
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
viewA.setText("tap");
return true;
}
}
Three things:
The View heirarchy of your activity comes from the main.xml file in your layout folder since you've written:
setContentView(R.layout.main);
in your code.You have not attached GestureListener to anything. How do you expect Callbacks to be invoked?