I want to get the integer from the editText and by pressing the button, show the input in textView. The problem is the result is always zero. Thanks in advance for your helps.
EditText editText = (EditText) findViewById(R.id.editText);
TextView textView = (TextView) findViewById(R.id.textView);
Button button = (Button) findViewById(R.id.button);
try{
String string = editText.getText().toString();
int num = Integer.parseInt(string);}
catch(NumberFormatException numb){
Toast.makeText(this, "Problem", Toast.LENGTH_SHORT).show();
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = String.valueOf(num);
textView.setText(number);
}
});