我是这里的 Android 新手,我不知道如何通过按下按钮将选定的微调器文本作为 SMS 文本传递给 SMS 以发送到选定的号码。如果有人可以在这里教我,我很高兴。
public class MainActivity extends Activity { //all starts here
String[] location;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
location = getResources().getStringArray(R.array.location_array);
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, location);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
int index = arg0.getSelectedItemPosition();
Toast.makeText(getBaseContext(), "You have selected " + location[index], Toast.LENGTH_SHORT).show();
}
public void onNothingSelected(AdapterView<?> arg0){}
});
}
public void onClick(View v) { //<--**HERE IS THE PROBLEM**
sendSMS("5556", "+location [index]"); //<--**HERE IS THE PROBLEM**
}
//?sends an SMS message to another device?
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}
//-必须在这里结束