나는 안드로이드 신참이다. 선택한 스피너 텍스트를 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);
}
}
// - 여기에서 끝나야합니다
이
sendSMS("5556", "+location [index]");
넣어 ("5556", "+ 위치 [인덱스]"); public void onItemSelected (AdapterView > arg0,보기 arg1, int arg2, long arg3) { int index = arg0.getSelectedItemPosition(); Toast.makeText (getBaseContext(), "선택한 위치 + 색인 [색인], Toast.LENGTH_SHORT) .show(); } – Akram@Ken 제 답변을 참조하십시오. 문제가 있다면 알려주십시오. –