【发布时间】:2017-05-20 19:11:22
【问题描述】:
我是 android studio 的新手,正在尝试发送一个仅通过 SMS 消息检查的值复选框。
我将值更改为String,因此尽管未选中所有值复选框都已发送
请帮我修复程序,以便仅选中的值复选框通过SMS 消息发送。
完整代码:
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(查看视图) {
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;
}
}
}
}
【问题讨论】:
-
您的具体问题是什么?
-
请...如何修复程序,以便仅选中的值复选框通过短信发送。谢谢