如何从下拉菜单中获取值并在要发送的新消息正文中使用它们。

以下是我的代码,

 public void onItemSelected(AdapterView<?> parent, View view, int position,
            long id) {
        // On selecting a spinner item
        String label = parent.getItemAtPosition(position).toString();
            // Showing selected spinner item
        Toast.makeText(parent.getContext(), "You selected: " + label,
                Toast.LENGTH_LONG).show();
        }
String phoneNo = editPhoneNum.getText().toString();
             String sms = editSMS.getText().toString();
             try {
                     SmsManager smsManager =    SmsManager.getDefault();
                     smsManager.sendTextMessage(phoneNo, null, sms, null, null);
                     Toast.makeText(getApplicationContext(), "SMS Sent!",Toast.LENGTH_LONG).show();


             }

最佳答案

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // On selecting a spinner item
            String label = parent.getItemAtPosition(position).toString();
                // Showing selected spinner item
            Toast.makeText(parent.getContext(), "You selected: " + label,Toast.LENGTH_LONG).show();

                }
}

关于android - 如何从android中的微调器获取值(value)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20988891/

10-09 06:09