Get button click on toolbar

0

I have two Save and Save buttons on my toolbar. I can not click. If I put the button click on the normal view I can get the click

private class btGravar implements View.OnClickListener {
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnSalvar:

                String nomeDesc = nome.getText().toString();
                String foneDesc = fone.getText().toString();
                String emailDesc = email.getText().toString();
                String ruaDesc = rua.getText().toString();

Can anyone help me?

    
asked by anonymous 28.11.2016 / 18:08

1 answer

0

Do this way to get the ToolBar clicks:

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.btnSalvar) {

        String nomeDesc = nome.getText().toString();
        String foneDesc = fone.getText().toString();
        String emailDesc = email.getText().toString();
        String ruaDesc = rua.getText().toString();

        return true;
    }

    return super.onOptionsItemSelected(item);
}
    
28.11.2016 / 18:37