I am wondering how to convert an edittext input to an int, I have the user input a number, it than divides it by 8.
MainActivity.java
@SuppressWarnin
First, find your EditText
in the resource of the android studio by using this code:
EditText value = (EditText) findViewById(R.id.editText1);
Then convert EditText
value into a string
and then parse the value to an int
.
int number = Integer.parseInt(x.getText().toString());
This will work
int total_Parson = Integer.parseInt(etRegularTickets.getText().toString());
int ticket_price=Integer.parseInt(TicketData.get(0).getTicket_price_regular());
total_ticket_amount = ticket_price * total_Parson;
etRegularPrice.setText(""+total_ticket_amount);
Try the line below to convert editText to integer.
int intVal = Integer.parseInt(mEtValue.getText().toString());
You can use like this
EditText dollar=(EditText) findViewById(R.id.money);
int rupees=Integer.parseInt( dollar.getText().toString());
Try this,
EditText x = (EditText) findViewById(R.id.editText1);
int n = Integer.parseInt(x.getText().toString());