2つの編集テキストにセットエラーのコードを実装しました。Seterrorシグナルが消えず、検索が正常に動作しています
- 最初にnull値または空の値がない文字列を取得する。
- nullまたは空の値を持たない文字列を取得するために2番目の値があり、いくつかのDouble値が必要です。私はときに私のエラーは、その後の最初の編集ボックスにポップアップし、検索ボタンを入力し、クリックしていないとき、すべての作業が良いだろうけどされていることを実施した後
import java.util.HashMap; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SearchPlaces extends Activity { EditText place; EditText distance; Button search; static String _place; static String _distance; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); place = (EditText) findViewById(R.id.place); distance = (EditText) findViewById(R.id.distance); search = (Button) findViewById(R.id.search); search.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Map<String, String> validate = new HashMap<String, String>(); _place = place.getText().toString(); _distance = distance.getText().toString(); validate.put("placename", _place); validate.put("distancenumeric", _distance); if (!validateInputInformation(validate)) { return; } if ((_place == "" && _distance == "")) { Toast.makeText(getApplicationContext(), "Please fill all the information", Toast.LENGTH_SHORT).show(); } else { _place = place.getText().toString(); _distance = distance.getText().toString(); Intent placedist = new Intent(getApplicationContext(), MainActivity.class); Bundle bundle = new Bundle(); bundle.putString("place", _place); bundle.putString("distance", _distance); placedist.putExtras(bundle); startActivity(placedist); } } private boolean validateInputInformation( Map<String, String> validate) { String l_place = validate.get("placename"); if (l_place == null || l_place.equals("")) { place.setError("Please enter the Place First"); return false; } String l_distance = validate.get("distancenumeric"); if (l_distance == null || l_distance.equals("")) { distance.setError("Please enter the Distance First"); return false; } if (!isDoubleNumber(l_distance)) { distance.setError("Please enter Numeric Value"); return false; } return true; } private boolean isDoubleNumber (String num) { try { Double.parseDouble(num); } catch (NumberFormatException nfe) { return false; } return true; } }); } }
を次のようにコードがある
必要な入力として正しい値を再入力してください。エラー通知は消えませんが、検索ボタンは正常に機能します。
設定エラー通知を最初の編集ボックスから削除できるように助けてください。
いいえ、それは私の別の問題を解決しましたが、まだ保留中です –
@VarunVishnoiあなたの2番目の問題は何ですか? –
最初の編集テキストで文字列を与えた後、seterrorの赤い記号が消えることはありませんが、すべての作業は順調です。その赤いエラーが消えていない –