How to restrict this function from execution in android? Please help

Posted by andyfan on Stack Overflow See other posts from Stack Overflow or by andyfan
Published on 2011-01-14T10:44:59Z Indexed on 2011/01/14 10:53 UTC
Read the original article Hit count: 158

Filed under:

This code is present in one of this activity. I want to restrict addJoke() function from executing if the String variable new_joke is null, has no text or contains just spaces. Here is code

protected void initAddJokeListeners() {
    // TODO
    m_vwJokeButton.setOnClickListener(new OnClickListener() {
        @Override
    public void onClick(View view) {
    //Implement code to add a new joke here...
            String new_joke=m_vwJokeEditText.getText().toString();
            if(new_joke!=null&&new_joke!=""&&new_joke!=" ")
            {
                addJoke(new_joke);
            }
        }
    });
}

I don't know why addJoke() function is getting executed even I don't enter any text in EditText field. Please help.

© Stack Overflow or respective owner

Related posts about android