我是Android的初学者。有一个带有imageview的屏幕,在图像上触摸3次,下一个活动应该出现..
请帮我解决这个问题 谢谢大家。
答案 0 :(得分:3)
你必须管理相同的计数。这样做:
int touchCount = 0;
ImageView img = (ImageView) findViewById(R.id.image);
img.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
touchCount = touchCount + 1;
if (touchCount == 3){
touchCount=0;
Intent intent = new Intent(mContext, ActivityA.class);
startActivity(intent);
}else{
Toast.makeText(getApplicationContext(),
"Click more"+ Integer.toString(3-touchCount) +" time to navigate next screen."),
Toast.LENGTH_LONG).show();
}
});
答案 1 :(得分:3)
ImageView img = (ImageView) findViewById(R.id.img);
img.setOnClickListener(new View.OnClickListener() {
private int clickCount;
@Override
public void onClick(View v) {
if (++clickCount == 3) {
Intent intent = new Intent(MainActivity.this, OtherActivity.class);
startActivity(intent);
}
}
});
MainActivity
的位置,是您当前活动的名称,OtherActivity
是您的目标。
答案 2 :(得分:1)
int click = 0;
image.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
click = click + 1;
if (click == 3){
click=0;
Intent intent = new Intent(Activity.this, nextActivity.class);
startActivity(intent);
}
});