我有一些代码,用户在 EditText 中输入数字。
根据他们输入的值,我想设置一个由对话框片段拉出的字符串(我现在已经用 toast 替换了,直到我可以修复字符串位。)
我得到了更改为 int 的俯卧撑输入。该 int 在其下方的逻辑中与某些标准进行比较。根据它落在哪里,我希望它更改一个字符串,一旦所有逻辑完成,该字符串将在稍后显示。
package com.mynavy;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class PRTC extends Activity {
String pushs;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prtc);
Button submit = (Button) findViewById(R.id.submit);
submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText age = (EditText) findViewById(R.id.agetxt);
EditText pushups = (EditText) findViewById(R.id.pushups);
EditText situps = (EditText) findViewById(R.id.situps);
EditText runtime = (EditText) findViewById(R.id.runtime);
String agetxt = String.valueOf(age.getText().toString());
int agen = Integer.valueOf(agetxt);
String pushtxt = String.valueOf(pushups.getText().toString());
int pushn = Integer.valueOf(pushtxt);
String sittxt = String.valueOf(situps.getText().toString());
int sitn = Integer.valueOf(sittxt);
String runtxt = String.valueOf(runtime.getText().toString());
int runn = Integer.valueOf(runtxt);
//CHANGE THESE WHEN NEW INSTRUCTIONS COME OUT!!
if (agen >= 17 || agen <=20) {
if (pushn >=20 || pushn <=30){
String pushs = "Good";
}else if (pushn >=31 || pushn <=40){
String pushs = "Excellent";
}else if (pushn >=41 || pushn <=50){
String pushs = "Outstanding";}}
if (sitn >= 20 || sitn <= 30){
String sits = "Good";
}else if (sitn >= 31 || sitn <=40){
String sits = "Excellent";
}else if (sitn >= 41 || sitn <=50){
String sits = "Outstanding";
Toast.makeText(getBaseContext(), pushs + "Score.", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getBaseContext(), "TEST FAILED!!", Toast.LENGTH_SHORT).show();
}
};});
}}
我知道我最近问了很多,但是提供的任何帮助都将一如既往地感激不尽!!