force user to fill in edittext

Asked

Viewed 492 times

1

I have some Edittext and I need them all filled in, in case the user does not fill in and try to press the button to continue the text boxes should show an error. put that button in the action bar and do not know where to apply the check

2 answers

1

Fala Carlos,

You are inflating an xml with your actionBar items, correct?

Something more or less like this:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);
   inflater.inflate(com.sample.R.menu.menu_main, menu);
}

So you have to have a method that controls clicks, example:

public boolean OnOptionItemSelected(MenuItem item){
    switch(item.getItemId()){
      case R.id.enviarForm:
          //verifica se o campo de texto está nulo
          return true;  
      default:
         return super.onOptionsItemSelected(item);
    }   
}

Hugs.

  • hi I just got home, I’m gonna test this, thanks for the help

  • I didn’t understand what R.id.send:

  • It is the id of the button (item) that you have there in your menu, which you inflated, put the XML of your menu for us to see.

0

But I would put a method, which checks whether the field is null or not, to be activated when the user clicks the Button.

Take a look at this link. I hope it helps. When validating fields of a swing form?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.