我,新的android可以任何人幫助我這個簡單的,但我不能識別這個執行process.I需要動態結果通過微調,但這裏微調執行while在運行時只(不點擊微調) 不好意思問這個問題不能即時解決這個... :(Android:通過微調器動態獲取結果
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.loanpayment);
try {
et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);
et3 = (EditText) findViewById(R.id.et3);
ans = (TextView) findViewById(R.id.editText1);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
s = (Spinner) findViewById(R.id.spin);
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
ArrayAdapter<String> a = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, values);
a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(a);
s.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String item = parent.getItemAtPosition(position).toString();
if(item.equals("Yearly")) {
Pattern p = Pattern.compile("([0-9 .]*)");
if (et1.getText().toString().trim().length() > 0 && et2.getText().toString().trim().length() > 0 && et3.getText().toString().trim().length() > 0) {
Matcher m = p.matcher(et1.getText().toString().trim());
Matcher m1 = p.matcher(et2.getText().toString().trim());
Matcher m2 = p.matcher(et3.getText().toString().trim());
if (m.matches() && m1.matches() && m2.matches()) {
amount = Float.valueOf(et1.getText().toString());
interest = Float.valueOf(et2.getText().toString());
year = Float.valueOf(et3.getText().toString());
s1 = interest/100;
s2 = year;
ans1 = s1 * amount;
ans2 = (float) (1-Math.pow((1+s1), -s2));
tot = (float) Math.round(ans1/ans2);
String an = Float.toString(tot);
ans.setText("Amount to Pay=" +an);
}
else {
Toast.makeText(getApplicationContext(),
"Incorrect value", Toast.LENGTH_SHORT)
.show();
}
我很困惑。你得到了什麼結果,你想要什麼結果? – codeMagic 2013-03-15 15:07:14
@ codeMagic--在程序中,我希望通過微調器動態生成結果,所以我在微調onItemSelected中編寫了程序。所以,在運行時它會執行微調而不考慮其他字段 – user2174439 2013-03-15 15:11:59
@codeMagic你能否用你的澄清解釋來更新你的問題? – rhughes 2013-03-15 15:17:18