Converting EditText to int? (Android)

前端 未结 11 1157
深忆病人
深忆病人 2020-12-09 03:08

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         


        
相关标签:
11条回答
  • 2020-12-09 03:51

    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

    0 讨论(0)
  • 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);
    
    0 讨论(0)
  • 2020-12-09 03:54

    Try the line below to convert editText to integer.

    int intVal = Integer.parseInt(mEtValue.getText().toString());
    
    0 讨论(0)
  • 2020-12-09 03:54

    You can use like this

     EditText dollar=(EditText) findViewById(R.id.money);
     int rupees=Integer.parseInt( dollar.getText().toString());
    
    0 讨论(0)
  • 2020-12-09 03:57

    Try this,

    EditText x = (EditText) findViewById(R.id.editText1);
    int n = Integer.parseInt(x.getText().toString());
    
    0 讨论(0)
提交回复
热议问题