我想在新邮件正文的编辑文本中插入我的下拉菜单选项,以便我可以编辑文本并根据需要进行必要的更新。我编辑文本的xml代码是:
<EditText
android:id="@+id/editSMS"
android:layout_width="fill_parent"
android:layout_height="132dp"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="9" />
从下拉菜单中选择项目的代码
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// On selecting a spinner item
label = parent.getItemAtPosition(position).toString();
// Showing selected spinner item
Toast.makeText(parent.getContext(), "You selected: " + label,
Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
和新邮件的代码
editSMS = (EditText) findViewById(R.id.editSMS);
public void onClick(View v) {
String phoneNo = editPhoneNum.getText().toString();
String sms = label + editSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"SMS faild, please try again later!",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
加载微调器数据的代码
private void loadSpinnerData() {
// database handler
DbHelper db = new DbHelper(getApplicationContext());
// Spinner Drop down elements
List<String> lables = db.getAllNames();
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, lables);
// Drop down layout style - list view with radio button
dataAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
答案 0 :(得分:0)
添加下拉项目选择的侦听器。首先将父级转换为适当的视图类,然后获取所选项
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// On selecting a spinner item
label = ((Spinner) parent).getSelectedItem().toString();
// Showing selected spinner item
Toast.makeText(parent.getContext(), "You selected: " + label,
Toast.LENGTH_LONG).show();
EditText etSMS= (EditText) findViewById(R.id.editSMS);
etSMS.setText(label);
}