I have just started to use android studio recently and currently I am working on a Roman Numeral Translator app. The app\'s interface looks like this: Application interface<
You need to make your TextView a class member and initialise it in your oncreate bundle, so that you can access the textview elsewhere in the activity.
TextView numeralInput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main);
numeralInput = (TextView) findViewById(R.id.textView);
convert.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
String intValue = numeralInput.getText().toString();
try{
int integer = Integer.parseInt(intValue);
if (integer > 0 && integer <= 4999){
translator(integer);
}else{
numeralInput.setText("Please enter an integer between 0 and 4,999.");
}
}catch(NumberFormatException e){
numeralInput.setText("Invalid input try again.");
}
}
}
);
Make your translator()
method return a string which contains the final output.
So before the while
statement in that method, declare a string such as
String result = null;
and in the loop append the popped values to this variable like, result += stack.pop()
.
Now, the place where you call the translator(integer)
method, do numeralInput.setText(translator(integer))
instead of translator(integer)