把你的程式碼,透過下面網頁進行轉碼就可以解決問題 :
沒轉碼過的程式碼 , 可以看到if判斷式後面開始出錯
public class Main3Activity extends AppCompatActivity {
private TextView txtheight,txtweight,txtresult;
private EditText sex,waistline;
private Button btncalculate;
private double height,weight;
private int intwaistline;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
findViews();
}
private void findViews(){
txtheight = (TextView)findViewById(R.id.txtheight);
txtweight = (TextView)findViewById(R.id.txtweight);
txtresult = (TextView)findViewById(R.id.result);
sex = (EditText)findViewById(R.id.sex);
waistline = (EditText)findViewById(R.id.waistline);
btncalculate = (Button)findViewById(R.id.btncalculate);
Bundle bundle = getIntent().getExtras();
height = bundle.getDouble("height");
String shieght = String.valueOf(height);
weight = bundle.getDouble("weight");
String sweight = String.valueOf(weight);
txtheight.setText(shieght);
txtweight.setText(sweight);
btncalculate.setOnClickListener(btncalculateListner);
}
private Button.OnClickListener btncalculateListner = new Button.OnClickListener(){
public void onClick(View view){
intwaistline = Integer.parseInt(waistline.getText().toString());
String ssex = sex.getText().toString();
switch (ssex){
case "F":
if(intwaistline<80 break="" case="" code="" default:="" else="" if="" intwaistline="" txtresult.settext="">80>
轉換格式後就正常了 :
public class Main3Activity extends AppCompatActivity {
private TextView txtheight,txtweight,txtresult;
private EditText sex,waistline;
private Button btncalculate;
private double height,weight;
private int intwaistline;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
findViews();
}
private void findViews(){
txtheight = (TextView)findViewById(R.id.txtheight);
txtweight = (TextView)findViewById(R.id.txtweight);
txtresult = (TextView)findViewById(R.id.result);
sex = (EditText)findViewById(R.id.sex);
waistline = (EditText)findViewById(R.id.waistline);
btncalculate = (Button)findViewById(R.id.btncalculate);
Bundle bundle = getIntent().getExtras();
height = bundle.getDouble("height");
String shieght = String.valueOf(height);
weight = bundle.getDouble("weight");
String sweight = String.valueOf(weight);
txtheight.setText(shieght);
txtweight.setText(sweight);
btncalculate.setOnClickListener(btncalculateListner);
}
private Button.OnClickListener btncalculateListner = new Button.OnClickListener(){
public void onClick(View view){
intwaistline = Integer.parseInt(waistline.getText().toString());
String ssex = sex.getText().toString();
switch (ssex){
case "F":
if(intwaistline<80)
txtresult.setText("正常體位");
else
txtresult.setText("體位異常");
break;
case "M":
if(intwaistline<90)
txtresult.setText("正常體位");
else
txtresult.setText("體位異常");
break;
default:
txtresult.setText("輸入錯誤");
}
}
};
}
另外如果是XML的格式,可以使用下面的網址轉換:
http://coderstoolbox.net/string/#!encoding=xml&action=encode&charset=us_ascii
沒有留言:
張貼留言