我正在尝试实现一个基于选项卡的视图,其中用户可以使用滑动手势在选项卡之间切换。但是,同一活动的多个实例会在滑动时打开。我怎样才能防止这种情况?谢谢
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
initialx=event.getX();
initialy=event.getY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
finalx=event.getX();
finaly=event.getY();
if (initialx>(finalx+150.0)){
RadioGroup Options = (RadioGroup) findViewById(R.id.vOptions);
int selectedId = Options.getCheckedRadioButtonId();
final EditText QuestionNo = (EditText)findViewById(R.id.vnumberofquestions);
final EditText Time = (EditText)findViewById(R.id.vtimeperquestion);
if ((QuestionNo.getText().toString().equals(" ")) || (Time.getText().toString().equals("")) ||(selectedId==-1)) {
Intent intenta=new Intent(VerbalSelect.this, TabDisplay.class );
intenta.putExtra("index", 0);
startActivity(intenta);
}
else {
RadioButton selectedButton = (RadioButton) findViewById(selectedId);
String testtype = (String) selectedButton.getText();
int questionno = Integer.parseInt(QuestionNo.getText().toString());
int timeperquestion = Integer.parseInt(Time.getText().toString());
long timeroffset = questionno*timeperquestion;
Intent intent=new Intent(VerbalSelect.this, Main.class);
intent.putExtra("testtype", testtype);
intent.putExtra("timeroffset",timeroffset);
intent.putExtra("questionno","1");
intent.putExtra("questionlimit", questionno);
startActivity(intent);
}
break;
}
}
return true;
}