I have 3 classes: MainActivity,DrawView and SecondActivity. MainActivity just use DrawView to draw something on the screen. How can I start SecondActivity when i touch the screen on an Bitmap, I know where is the bitmap(in the code). The onTouchEvent function from DrawView class.
@Override
public boolean onTouchEvent(final MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
float posX = ev.getX();
float posY = ev.getY();
if(play.touched(posX, posY)==true){
} 开发者_高级运维else {
}
return true;
}
}
return false;
}
The function play.touched(posX,posY)
return a boolean value(I made a class that handel the position of the Bitmap). How can I start Second Activity from here?
if(play.touched(posX, posY)){
Intent intent = new Intent(getContext(), SecondActivity.class);
((Activity)getContext()).startActivity(intent);
} else {
}
Have you tried:
if(play.touched(posX, posY)){
Intent intent = new Intent(getContext(), SecondActivity.class);
super.getContext().startActivity(intent);
} else {
}
精彩评论