Im currently trying to convert my Java code to function within an android app.
There are currently 3 classes, DecisionMap, DecisionNode and Utils. What the code does is that it builds a decision map from an unordered CSV file and then the user can navigate it by typing in either 1 or 2. The code works fine but for the life of me I cant get the buttons to navigateMap().
My original intent was to add another paramater into navigateMap as the which would be gotten from onClick but apparently you cant get a return from it?
The code for MainActivity.java :
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button yesButton = findViewById(R.id.yesButton);
yesButton.setOnClickListener(this);
final Button noButton = findViewById(R.id.noButton);
noButton.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.yesButton:
System.out.println("YES IS CLICKED");
break;
case R.id.noButton:
System.out.println("NO IS CLICKED");
break;
}
}
And the code im trying to implement:
public class DecisionMapTest {
public static void main(String[] args) throws FileNotFoundException {
Utils u = new Utils();
Scanner choice = new Scanner(System.in);
DecisionMap perec;
try {
perec = new DecisionMap();
} catch(FileNotFoundException fe){
u.console("File not found");return;
}
u.lineBreak();
u.console("Start...");
navigateMap(u, perec);
}
public static void navigateMap(Utils u, DecisionMap perec){
DecisionNode node = perec.entryPoint();
while(node != null) {
u.console(node.getDescription());
u.console(node.getQuestion());
if ( node.getQuestion().equals("-")) {
u.pressEnterToContinue();
node = node.getYesNode();
} else {
int decision = u.fromConsoleGetInt("Yes or No? (press 1 for Yes or 2 No)");
switch (decision) {
case 1:
node = node.getYesNode();
break;
case 2:
node = node.getNoNode();
break;
}
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…