lundi 28 août 2017

Can not solve my IF condition about isChecked

What is wrong with my code? My condition doesn't end when I check if the radio button is checked I want to make 3 options :

  • radio button 1 is checked -> end of condition
  • radio button 2 is checked -> end of condition
  • none of them checked -> toast messeage

code:

package com.ofekb.app_pt1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class settings extends AppCompatActivity {


    Button btnWaitress;
    EditText etSalaryWaitress;
    EditText etSalaryBartender;
    //------------
    RadioButton rbPercentage;
    RadioButton rbShekel;
    int HafrashaP;
    int HafrashaS;
    int etSWNum;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        btnWaitress =(Button)findViewById(R.id.btnWaitress);
        etSalaryWaitress = (EditText) findViewById(R.id.etSalaryWaitress);
        etSWNum = Integer.parseInt(etSalaryWaitress.getText().toString());
        etSalaryBartender = (EditText) findViewById(R.id.etSalaryBartender);
        //-----------
        rbPercentage = (RadioButton)findViewById(R.id.rbPercentage);
        rbShekel = (RadioButton)findViewById(R.id.rbShekel);

    }
    public void onClickWait (View v) {

        if (rbPercentage.isChecked()) {
            HafrashaP = 1 - (etSWNum / 100);
        }   else if (rbShekel.isChecked()) {
                HafrashaS = - etSWNum;
            }  else {
                    findViewById(R.id.btnWaitress).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Toast.makeText(settings.this, "XXXXXX", Toast.LENGTH_SHORT).show();
                        }
                    });
                    }
    }
}

Aucun commentaire:

Enregistrer un commentaire