Varun Vishnoi Varun Vishnoi - 1 year ago 69
Android Question

Seterror signal is not disappearing and Search is working

I have implemented the code of set error on two edit text.

  • First to get any string without null or empty value.

  • Second to get any string without null or empty value and must have some Double value.

Code is as follows

import java.util.HashMap;
import java.util.Map;

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;

public void onCreate(Bundle savedInstanceState) {

place = (EditText) findViewById(;
distance = (EditText) findViewById(;
search = (Button) findViewById(;
search.setOnClickListener(new View.OnClickListener() {

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)) {
if ((_place == "" && _distance == "")) {
"Please fill all the information",
} else {
_place = place.getText().toString();
_distance = distance.getText().toString();
Intent placedist = new Intent(getApplicationContext(),
Bundle bundle = new Bundle();

bundle.putString("place", _place);
bundle.putString("distance", _distance);


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 {
} catch (NumberFormatException nfe) {
return false;
return true;

after implementing that all working are going good but when I doesn't enter and click search button the error pops up in first edit-box after that when I reenter the correct values as input needed then the error notification doesn't disappear but search button works good.

Please help me so that the set-error notification can be removed from the first editbox.

Answer Source

Write below code line instead of if ((_place == "" && _distance == "")), it will solve your problem.

if (_place.equals("") && _distance.equals(""))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download