hello guys im newbie in android i want just to change the text view text if the caculate value between 18 or 25 i used if statment but there is no results any idea sometimes if i removed one of the >its worked but only for biggest value
public class GB extends ActionBarActivity {
ImageView im1;
EditText mEditText1,mEditText2;
TextView mTextView,m5;
Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_GB);
im1 = (ImageView)findViewById(R.id.imageView1);
mEditText1 = (EditText)findViewById(R.id.editText1);
mEditText2 = (EditText)findViewById(R.id.editText2);
mTextView = (TextView)findViewById(R.id.textView4);
m5 = (TextView)findViewById(R.id.textView5);
mButton = (Button)findViewById(R.id.button1);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
}
String word2 = mEditText2.getText().toString();
String word = mEditText1.getText().toString();
if (word.trim().equals("")){
mEditText1.setError("Insert Hight");
}
else if (word2.trim().equals("")){
mEditText2.setError("Insert Wight");
}
else{
calculate();
}
}});
}
public void calculate(){
Double value1 = Double.parseDouble(mEditText1.getText().toString());
Double value2 = Double.parseDouble(mEditText2.getText().toString());
Double calculatedValue = value1/(value2*value2)*10000;
calculatedValue = Math.round(calculatedValue*10)/10.0d;
mTextView.setText(calculatedValue.toString());
if (mTextView.getText().toString().trim().length() <10 && mTextView.getText().toString().trim().length() >18) {
im1.setBackgroundResource(R.drawable.s1);
m5.setText("low");}
else{
if (mTextView.getText().toString().trim().length() <18 && mTextView.getText().toString().trim().length() >25) {
im1.setBackgroundResource(R.drawable.s3);
m5.setText("Best");}
else {
if(mTextView.getText().toString().trim().length() <25 && mTextView.getText().toString().trim().length() >100) {
im1.setBackgroundResource(R.drawable.s3);
m5.setText("over");
} ;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire