Saturday, 19 August 2017

Create Check Box


public class CheckboxActivity extends AppCompatActivity {

    Button button_order;
    CheckBox checkBox1,checkBox2,checkBox3;
    Spinner spinner;
    AutoCompleteTextView autoCompleteTextView;

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

        final String[] country={"India","Packistan","Srilanka","Nepal","West Bengal"};

        button_order=(Button)findViewById(R.id.button_order);

        checkBox1=(CheckBox)findViewById(R.id.checkBox1);
        checkBox2=(CheckBox)findViewById(R.id.checkBox2);
        checkBox3=(CheckBox)findViewById(R.id.checkBox3);
        spinner=(Spinner)findViewById(R.id.spinner);
        autoCompleteTextView=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);

        String value=getIntent().getStringExtra("name");

        Log.d("checkbox activity",value);

        Toast.makeText(getApplicationContext(),"*******"+value,Toast.LENGTH_LONG).show();

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

                int totalAmount=0;
                StringBuilder result=new StringBuilder();

                if(checkBox1.isChecked()){
                    result.append("Pizza 100Rs");
                    totalAmount+=100;
                }

                if(checkBox2.isChecked()){
                    result.append("\nCoffee 50Rs");
                    totalAmount+=50;
                }

                if(checkBox3.isChecked()){
                    result.append("\nBurger 150Rs");
                    totalAmount+=150;
                }

                alertMessage(result);
               // result.append("\n Total Amount="+totalAmount);
                //Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();

            }
        });


        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,country);
        spinner.setAdapter(adapter);


        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getApplicationContext(),country[position],Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        autoCompleteTextView.setAdapter(adapter);
        autoCompleteTextView.setThreshold(1);
        autoCompleteTextView.setTextColor(Color.BLUE);

    }

    private void alertMessage(StringBuilder result){

        AlertDialog.Builder builder=new AlertDialog.Builder(this);

        builder.setMessage("Do u want to do this order \n"+result).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                })


                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();

                    }
                });

        builder.setTitle("Order Menu");
        builder.show();

    }

}

No comments:

Post a Comment

HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...