jeudi 5 janvier 2017

android studio value check box, only checked send from message

I'm new android studio

try to send a value checkbox that only checked via sms message.

I change the value to String so all value checkbox sent though it's unchecked

please help me how to fix the program so that the value checkbox only checked are sent via sms message. Thanx

full code :

private EditText qty1, qty2,qty3,qty4,qty5,qty6;
private CheckBox cos5,cos10,cos20,cos25,cos50,cos100;
private Spinner spinnerrs;
private Button buttonsendtrx;



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

    qty1 = (EditText)findViewById(R.id.editTextQty1);
    qty2 = (EditText)findViewById(R.id.editTextQty2);
    qty3 = (EditText)findViewById(R.id.editTextQty3);
    qty4 = (EditText)findViewById(R.id.editTextQty4);
    qty5 = (EditText)findViewById(R.id.editTextQty5);
    qty6 = (EditText)findViewById(R.id.editTextQty6);
    cos5 =(CheckBox)findViewById(R.id.S05);
    cos10=(CheckBox)findViewById(R.id.S10);
    cos20=(CheckBox)findViewById(R.id.S20);
    cos25=(CheckBox)findViewById(R.id.S25);
    cos50=(CheckBox)findViewById(R.id.S50);
    cos100=(CheckBox)findViewById(R.id.S100);



    buttonsendtrx = (Button) findViewById(R.id.buttonsendtrx);
    addItemOnSpinner();

     buttonsendtrx.setOnClickListener(new View.OnClickListener(){
         public void onClick(View view) {
            CheckBox cb = (CheckBox) view;

            if (view==buttonsendtrx);
             {
                 sendsms();
             }
         }
     });
    }







public void sendsms () {

    Log.i("Send SMS","");
    String nomor = spinnerrs.getSelectedItem().toString();
    String jumlah1 = qty1.getText().toString();
    String jumlah2 = qty2.getText().toString();
    String jumlah3 = qty3.getText().toString();
    String jumlah4 = qty4.getText().toString();
    String jumlah5 = qty5.getText().toString();
    String jumlah6 = qty6.getText().toString();
    String s5 = cos5.getText().toString();
    String s10 = cos10.getText().toString();
    String s20 = cos20.getText().toString();
    String s25 = cos25.getText().toString();
    String s50 = cos50.getText().toString();
    String s100 = cos100.getText().toString();


    {
        try {
            SmsManager smsManager = SmsManager.getDefault();

            smsManager.sendTextMessage(nomor, null, s5+jumlah1+s10+jumlah2+s20+jumlah3+s25+jumlah4+s50+jumlah5+s100++jumlah6, null, null);
            Toast.makeText(getApplicationContext(), "SMS SEND", Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "SMS FAILED,PLEASE TRY AGAIN", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }

    }
}

public void addItemOnSpinner() {
    spinnerrs = (Spinner) findViewById(R.id.spinnerrs);
    List<String> kategori = new ArrayList<String>();
    kategori.add("08127648200");
    kategori.add("081276482000");
    kategori.add("081275250000");
    ArrayAdapter<String> dataadapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,kategori);
    dataadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerrs.setAdapter(dataadapter);
}

public void selectItem(View view) {

    boolean checked = ((CheckBox) view).isChecked();

    switch (view.getId())
    {
        case R.id.S05:

        if (checked){
            qty1.setBackgroundColor(Color.parseColor("#FFFFFF"));
            qty1.setFocusable(true);
            qty1.setFocusableInTouchMode(true);
            qty1.setCursorVisible(true);
            qty1.setEnabled(true);
            qty1.setVisibility(view.VISIBLE);
            break;
        }
        else {
            //selection.remove(String.valueOf(cos5));
            qty1.setBackgroundColor(Color.parseColor("#CCCCCC"));
            //qty1.setTextIsSelectable(false);
            qty1.setFocusable(false);
            qty1.setFocusableInTouchMode(false);
            qty1.setCursorVisible(false);
            qty1.setEnabled(false);
            qty1.setVisibility(view.INVISIBLE);
            break;
        }

        case R.id.S10:
            if (checked){
                qty2.setBackgroundColor(Color.parseColor("#FFFFFF"));

                qty2.setFocusable(true);
                qty2.setFocusableInTouchMode(true);
                qty2.setCursorVisible(true);
                qty2.setEnabled(true);
                qty2.setVisibility(view.VISIBLE);

                break;
            }
            else {
                qty2.setBackgroundColor(Color.parseColor("#CCCCCC"));

                qty2.setFocusable(false);
                qty2.setFocusableInTouchMode(false);
                qty2.setCursorVisible(false);
                qty2.setEnabled(false);
                qty2.setVisibility(view.INVISIBLE);
                break;
            }

        case R.id.S20:
            if (checked){
                qty3.setBackgroundColor(Color.parseColor("#FFFFFF"));

                qty3.setFocusable(true);
                qty3.setFocusableInTouchMode(true);
                qty3.setCursorVisible(true);
                qty3.setEnabled(true);
                qty3.setVisibility(view.VISIBLE);

                break;
            }
            else {
                qty3.setBackgroundColor(Color.parseColor("#CCCCCC"));

                qty3.setFocusable(false);
                qty3.setFocusableInTouchMode(false);
                qty3.setCursorVisible(false);
                qty3.setEnabled(false);
                qty3.setVisibility(view.INVISIBLE);
                break;
            }

        case R.id.S25:
            if (checked){
                qty4.setBackgroundColor(Color.parseColor("#FFFFFF"));

                qty4.setFocusable(true);
                qty4.setFocusableInTouchMode(true);
                qty4.setCursorVisible(true);
                qty4.setEnabled(true);
                qty4.setVisibility(view.VISIBLE);

                break;
            }
            else {
                qty4.setBackgroundColor(Color.parseColor("#CCCCCC"));
                //qty4.setTextIsSelectable(false);
                qty4.setFocusable(false);
                qty4.setFocusableInTouchMode(false);
                qty4.setCursorVisible(false);
                qty4.setEnabled(false);
                qty4.setVisibility(view.INVISIBLE);
                break;
            }
            case R.id.S50:
            if (checked){
                qty5.setBackgroundColor(Color.parseColor("#FFFFFF"));
                //qty5.setTextIsSelectable(true);
                qty5.setFocusable(true);
                qty5.setFocusableInTouchMode(true);
                qty5.setCursorVisible(true);
                qty5.setEnabled(true);
                qty5.setVisibility(view.VISIBLE);
                break;
            }
            else {
                qty5.setBackgroundColor(Color.parseColor("#CCCCCC"));
                qty5.setFocusable(false);
                qty5.setFocusableInTouchMode(false);
                qty5.setCursorVisible(false);
                qty5.setEnabled(false);
                qty5.setVisibility(view.INVISIBLE);
                break;
            }
        case R.id.S100:
            if (checked){
                qty6.setBackgroundColor(Color.parseColor("#FFFFFF"));
                qty6.setFocusable(true);
                qty6.setFocusableInTouchMode(true);
                qty6.setCursorVisible(true);
                qty6.setEnabled(true);
                qty6.setVisibility(view.VISIBLE);
                break;
            }
            else {
                qty6.setBackgroundColor(Color.parseColor("#CCCCCC"));
                qty6.setFocusable(false);
                qty6.setFocusableInTouchMode(false);
                qty6.setCursorVisible(false);
                qty6.setEnabled(false);
                qty6.setVisibility(view.INVISIBLE);
                break;
            }

    }

}

}




Aucun commentaire:

Enregistrer un commentaire