I want to know that if I have two activities in a program then how can I switch between two activities using ontouchlistener, just only touching anywhere on the screen?
public class V19 extends Activity implements OnTouchListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay19);
}
@Override
public boolean onTouch(View to_main, MotionEvent event) {
return false;
}
}
You can use layout inflater and method setContentView(View v)
public class V19 extends Activity implements OnTouchListener{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = getLayoutInflater().inflate(R.layout.lay19, null); setContentView(view); view.setOnTouchListener(this); } @Override public boolean onTouch(View to_main, MotionEvent event) { Intent i = new Intent(this, Activity2.class); startActivity(i); return false; } }And than you can catch all touch events.
Other way is to override
public boolean dispatchTouchEvent (MotionEvent ev)method. Reference says: