This is my activity.xml
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inputnumber"
android:inputType="number" />
this is mainactivity.java
:
EditText num = (EditText) findViewById(R.Id.inputnumber) ;
the question is how can I get the integer value from this field as an integer and use it for example in a custom class I made like this to add 1 to the value of this input field?
my customclass.java
public static int addone(int a)
{
int b = a+1;
return b;
}
// Comment, you need to have added your EditText in your xml layout file for the activity for the previous line to //work // To get the String from the EditText do: mNumberString = mNumber. getString(); //Then you can parse this String to an Integer: int value = Integer. parseInt(mNumberString); I hope this helps.
The Best Answer is you have to used. String value= et. getText(). toString(); int finalValue=Integer.
getText() method and the other one is . setText() method that we use to set some pre-written text or string. EditText demo; demo=(EditText)findViewById(R. id.
you can achieve this as
int val = Integer.parseInt( num.getText().toString() );
and than pass val
to the method addone(val);
Get it beautiful
yourButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkEmptyFileds(txt_birey_adet, txt_limit)) {
int girilenSayi = Integer.parseInt(txt_birey_adet.getText().toString());
int limit = Integer.parseInt(txt_limit.getText().toString());
}
}
});
private boolean checkEmptyFileds(EditText txt_birey_adet, EditText txt_limit) {
boolean onay = true;
if (txt_birey_adet.getText().toString().equals("")) {
// Util.getInstance(OzelHesap.this).bounceEffect3(txt_birey_adet);
onay = false;
} else if (txt_limit.getText().toString().equals("")) {
//Util.getInstance(OzelHesap.this).bounceEffect3(txt_limit);
onay = false;
}
return onay;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With