Recent Posts

ANDROID STUDIO APP-DEV | COMPUTE TWO CHECKBOX


public class MainActivity extends AppCompatActivity {

    CheckBox menu1,menu2;
    Button order;
    TextView result;
    int Burger,Fries,total;

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

        menu1 = (findViewById(R.id.apple_id));
        menu2 = (findViewById(R.id.orange_id));
        total = (findViewById(R.id.order_id));
        result = (findViewById(R.id.result_id));

        order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if (menu1.isChecked()) {
                    Burger = 75;
                    total();
                }
                else{
                    Burger = 0;
                    total();
                }

                if (Menu2.isChecked()) {
                    Fries = 45;
                    total();
                }
                else{
                    Fries = 0;
                    total();
                }
                }
        });

    }

    public void total(){
        total = Burger + Fries;
        result.setText(String.valueOf(total));
    }
}


ANDROID STUDIO APP-DEV | COMPUTE TWO CHECKBOX ANDROID STUDIO APP-DEV | COMPUTE TWO CHECKBOX Reviewed by JARM is Life on January 19, 2020 Rating: 5

No comments:

Powered by Blogger.