伊莉討論區
標題:
有關於圖片
[打印本頁]
作者:
whitefat123
時間:
2016-7-26 03:12 PM
標題:
有關於圖片
請問各位大大 我這裡有簡單的程式 我想要做的圖片顯示是 當BMI達到 < 18.5 會顯示一張圖片,然後圖片顯示5秒會消失,但是做不太出來,想請教各位大大一下
這是我程式碼
package
com.example.master.healthy;
import
android.os.Bundle;
import
android.support.v7.app.AppCompatActivity;
import
android.view.View;
import
android.widget.Button;
import
android.widget.CheckBox;
import
android.widget.EditText;
import
android.widget.ImageView;
import
android.widget.TextView;
public class
MainActivity
extends
AppCompatActivity {
private
ImageView
imageView
;
@Override
protected void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.
activity_main
);
Button btn = (Button) findViewById(R.id.
button
);
btn.setOnClickListener(
listener
);
Button btn2 = (Button) findViewById(R.id.
button
);
btn2.setOnClickListener(
listener
);
}
public
View.OnClickListener
listener
=
new
View.OnClickListener() {
public void
onClick(View v) {
double
height, weight, bmi, bodyweight =
0
;
EditText txtHeight = (EditText) findViewById(R.id.
txtHeight
);
EditText txtWeight = (EditText) findViewById(R.id.
txtWeight
);
height = Double.
parseDouble
(txtHeight.getText().toString());
weight = Double.
parseDouble
(txtWeight.getText().toString());
height = height /
100.00
;
bmi = weight / (height * height);
CheckBox men = (CheckBox) findViewById(R.id.
checkBox
);
if
(men.isChecked()) {
bodyweight =
62
+ (height -
1.7
) *
0.6
;
}
CheckBox lady = (CheckBox) findViewById(R.id.
checkBox2
);
if
(lady.isChecked()) {
bodyweight =
52
+ (height -
1.58
) *
0.5
;
}
//bodyweight = (height * height) * 22;
TextView output = (TextView) findViewById(R.id.
lblOutput
);
output.setText(Double.
toString
(bmi));
TextView output2 = (TextView) findViewById(R.id.
lblOutput2
);
output2.setText(Double.
toString
(bodyweight));
}
};
}
作者:
syking7637
時間:
2016-8-25 02:06 PM
你可以加上這個試試!!
new Handler().postDelayed(new Runnable(){
public void run()
{
//圖片消失
}
}, 5000);
歡迎光臨 伊莉討論區 (http://www.eyny.com/)
Powered by Discuz!