我無法將焦點設置於第一場的EditText(它下面的其他3中)。代碼是:無法將焦點置於第一個edittext字段?
k1_e=(EditText)findViewById(R.id.k1_editText);
k1_e.requestFocusFromTouch();
try{
k1=Float.parseFloat(k1_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
k2_e=(EditText)findViewById(R.id.k2_editText);
try{
k2=Float.parseFloat(k2_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
al_e=(EditText)findViewById(R.id.al_editText);
try{
al=Float.parseFloat(al_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
alconst_e=(EditText)findViewById(R.id.al_const_editText);
try{
al_const=Float.parseFloat(alconst_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
當仿真器上執行的應用程序,它會自動將焦點設置到最後的EditText字段和拋出異常爲:
12-29 08:10:05.241: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
12-29 08:10:05.261: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
12-29 08:10:05.261: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
12-29 08:10:05.271: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
什麼是error.I是一個beginner.pls幫助
k1_e.getText()toString()返回 「」,它不能轉換爲浮點數 –
edittext.requestFocus(); programaticaly寫這個..爲什麼使用touchfocus .. – QuokMoon