Here i am using two EditTexts for getting some number as integer value ..
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
Now Im planning to do some calculation
some
int i1,i2,i3;
String t1,t2,t3;
EditText et1,et2,et3;
int result,comp;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et1=(EditText)findViewById(R.id.editText1);
et2=(EditText)findViewById(R.id.editText2);
et3=(EditText)findViewById(R.id.editText3);
//and also storing to string like
t1=et1.getText().toString();
t2=et2.getText().toString();
t3=et3.getText().toString();
i1=Integer.parseInt(t1);
i2=Integer.parseInt(t2);
i3=Integer.parseInt(t3);
comp=i2-i1;
}
/here int some x=10; my problem is how to check conditions i need to get comp value if its selected (by entering on two EditTexts) else One editText(i3 valsu)
any one help me …./
public int CalculateUsage(int customersUsage)
{
int x=10;
comp= customersUsage;
if(comp!=0)
{
customersUsage=comp;
result=(customersUsage*x) ;
}
else if(i3 !=null)
{
customersUsage=i3;
result=(customersUsage*x) ;
}
}
Integer.parseInt() throws an Exception if the String representation isn’t actually an integer. You should make a try-catch block and should set the values to 0 respectively, or the desired default value
Because the edit text value is currently “[empty]”.
EDIT:
The edit text are currently empty because you haven’t yet set anything to them.
The ems=”10″ that you have in you layout isn’t the edit text value.