Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:25:36+00:00 2026-06-15T23:25:36+00:00

I am having a problem with setError() on EditText . When an activity is

  • 0

I am having a problem with setError() on EditText. When an activity is opened, it checks if certain fields are empty and sets error message on them if true. However, the exclamation mark icon is only displayed in case I write some text in field and then delete it. If I lose focus on that field, the icon will disappear again. Both fields Naam and Telefonnumer have this validation.

I use Android 2.2.2 SDK and the application is run on Nexus 7 with latest updates.

I have Util class:

public class Util {

    private static String TAG = "Util Class";

    public static boolean editTextIsEmpty(EditText edittext) {
        if (edittext.getText().toString().trim().length() < 1)
            return true;
        else
            return false;
    }

    public void editTextListener(final EditText editText) {
        editText.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                if (editTextIsEmpty(editText) && editText.isEnabled())
                    editText.setError("Nodig");
                else
                    editText.setError(null);
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (editTextIsEmpty(editText) && editText.isEnabled())
                    editText.setError("Nodig");
                else
                    editText.setError(null);
            }
        });
    }
}

and then I have method validateInput() in my activity:

public class DeliveryActivity extends BaseActivity {

    private ImageButton btnSetDate;

    private Button btnToSummary;
    private Button btnSearchAddress;

    private EditText txtPostcode;
    private EditText txtHouseNumber;
    private EditText txtHouseNumberSuffix;
    private EditText txtStreet;
    private EditText txtCity;
    private EditText txtDeliveryDate;
    private EditText txtName;
    private EditText txtPhone;
    private EditText txtEmail;
    private EditText txtRemark;

    private TextView lblExtraDeliveryInfo;

    private Spinner spinnerDelivery;
    private Spinner spinnerDeliveryPeriod;
    private Spinner spinnerContact;
    private Spinner spinnerDeliveryAddress;
    private Spinner spinnerExtraDeliveryInfo;

    private RelativeLayout rlDeliveryAddressDetails;

    private DevRestHelper additionalDeliveryInfo;
    private DevRestHelper searchClientAddress;

    private Util util = new Util();

    private int year;
    private int month;
    private int day;

    public static final int DIALOG_DATEPICKER = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_delivery);

        initControls();

        validateInput();
    }

    private void initControls() {
        btnSetDate = (ImageButton) findViewById(R.id.activity_delivery_btnCalendar);

        btnToSummary = (Button) findViewById(R.id.activity_delivery_btnSummary);
        btnSearchAddress = (Button) findViewById(R.id.activity_delivery_btnSearchAddress);

        spinnerDelivery = (Spinner) findViewById(R.id.activity_delivery_spinnerDeliveryMethod);
        spinnerDeliveryPeriod = (Spinner) findViewById(R.id.activity_delivery_spinnerDeliveryPeriod);
        spinnerContact = (Spinner) findViewById(R.id.activity_delivery_spinnerContactperson);
        spinnerDeliveryAddress = (Spinner) findViewById(R.id.activity_delivery_spinnerDeliveryAddress);
        spinnerExtraDeliveryInfo = (Spinner) findViewById(R.id.activity_delivery_spinnerExtraDeliveryInformation);

        txtPostcode = (EditText) findViewById(R.id.activity_delivery_txtPostcode);
        txtHouseNumber = (EditText) findViewById(R.id.activity_delivery_txtHousenumber);
        txtHouseNumberSuffix = (EditText) findViewById(R.id.activity_delivery_txtHousenumberSuffix);
        txtStreet = (EditText) findViewById(R.id.activity_delivery_txtStreet);
        txtCity = (EditText) findViewById(R.id.activity_delivery_txtCity);
        txtDeliveryDate = (EditText) findViewById(R.id.activity_delivery_txtDeliveryDate);
        txtName = (EditText) findViewById(R.id.activity_delivery_txtName);
        txtPhone = (EditText) findViewById(R.id.activity_delivery_txtPhone);
        txtEmail = (EditText) findViewById(R.id.activity_delivery_txtEmail);
        txtRemark = (EditText) findViewById(R.id.activity_delivery_txtRemark);

        lblExtraDeliveryInfo = (TextView) findViewById(R.id.activity_delivery_lblExtraDetailInformation);

        rlDeliveryAddressDetails = (RelativeLayout) findViewById(R.id.activity_delivery_rlDeliveryAddressDetails);
    }

    private void validateInput() {
        util.editTextListener(txtPostcode);
        util.editTextListener(txtHouseNumber);
        util.editTextListener(txtDeliveryDate);
    }
}

Let me just say that code work on BlueStacks emulator.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:25:37+00:00Added an answer on June 15, 2026 at 11:25 pm

    There is a known bug with setError on Jelly Bean_MR1 (4.2 and 4.2.1). I am however assuming that the Nexus 7 you are testing with is running one of those versions of Android. See here: http://code.google.com/p/android/issues/detail?id=40417

    The error will be shown while you have focus on that EditText field, but when you lose focus, the error icon is not visible to notify the user of the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im having problem whith a POST request. I have to receive an XML message
Having problem understanding Delegate error. Error says expression expected, How do I fix? Thanks
having problem with null pointer exception and i read few article bout that error
I am having problem of showing Toast Message when i click a button within
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
I am having problem with previewing custom performance counters with PerflibV2. Performance Monitor shows
I am having problem to get a numerical value for this expression where I
I'm having problem with datagrid view. I have attached an image with the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.