0
我目前正在Android Studio中的一個學校項目,到目前爲止我已經寫了一個代碼生成一個隨機方程。現在我想顯示兩個方程,用戶必須決定哪一個具有更大的結果。如果第二個方程式更大,用戶必須做一個向上滑動,如果第二個方程式更小,則向下滑動。 下面是隨機方程代碼:多個如果條件與滑動事件
String[] operationSet = new String[]{"+", "-", "/", "*"};
String stringResultOfEquation;
String equation;
double doubleAnswer1;
public void start1() {
Random random = new Random();
int numOfOperations = random.nextInt(2) + 1;
List<String> operations = new ArrayList<>();
for (int i = 0; i < numOfOperations; i++) {
String operation = operationSet[random.nextInt(4)];
operations.add(operation);
}
int numOfNumbers = numOfOperations + 1;
List<Integer> numbers = new ArrayList<>();
for (int i = 0; i < numOfNumbers; i++) {
int number = random.nextInt(10)+1;
numbers.add(number);
}
String equation = "";
for (int i = 0; i < numOfOperations; i++) {
equation += numbers.get(i);
equation += operations.get(i);
}
equation += numbers.get(numbers.size() -1);
TextView TextEquation = (TextView)findViewById(R.id.textView3);
TextEquation.setText(equation);
String stringResultOfEquation = String.valueOf(equation);
double doubleAnswer1 = eval(stringResultOfEquation);
String stringAnswer = Double.toString(doubleAnswer1);
TextView textAnswer = (TextView)findViewById(R.id.textView4);
textAnswer.setText(stringAnswer);
}
但是我不知道怎麼寫代碼的刷卡事件。我想多的,如果像條件:
if((doubleAnswer1 > doubleAnswer2) && (MotionEvent.ACTION_DOWN = true)){
//create new equation
}
而對於所有其他possibilty(doubleAnswer1 < doubleAnswer2),以及如果MotionEvent被做了錯誤的方向。 我試圖這樣做,但它沒有奏效,所以我現在不知道該怎麼試。也許有人有一個想法如何解決這個問題。
如果有什麼是我的問題不清楚,請隨時問,我會試圖澄清這一問題:)
感謝您事先已經對你有所幫助!
以及如何使用這個對我的代碼,如果doubleAnswer1> doubleAnswer2或其他方式輪? – zutru
這段代碼是要檢測用戶做了什麼,你必須將它設置爲你的textViews,並且在OnFling方法中,你要檢查它是否正確。 – cuoka