我创建了这个小程序,允许用户在EditText中输入数值。
请帮帮我。
public class BidActivity extends Activity implements OnClickListener {
public TextView tt;
public EditText textbo;
public String total;
public Button btnnn;
public Double protein;
double price = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textbo = (EditText)findViewById(R.id.txtbid);
tt = (TextView)findViewById(R.id.textView1);
btnnn = (Button)findViewById(R.id.btnbit);
btnnn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String total = textbo.getText().toString();
price = Double.parseDouble(textbo.getText().toString());
//tt.setText("double: "+price);
if(Double.parseDouble(textbo.getText().toString()) < price){
tt.setText("double: "+price);
}else{
tt.setText("double: "+Double.parseDouble(textbo.getText().toString()));
}
}
}
答案 0 :(得分:1)
我猜你正在努力做到这一点:
double price = 0;
double savedPrice = 0.0;
...
@Override
public void onClick(View v) {
price = Double.parseDouble(textbo.getText().toString());
if(savedPrice < price){
tt.setText("double: "+price);
savedPrice = price;
}
// Otherwise leave tt as it is
}