2012-05-17 2 views
0

3 개의 버튼이있는 앱을 만들었습니다. 하나는 전화를 걸고, 하나는 이메일을 보내고 세 번째는 SMS를 보냅니다. 처음 만들었을 때, 나는 응답하지 않는 이메일 버튼을 알아 차렸다. 나는 어리석은 것을 발견하려고 노력했다. 그러나 couldnt. 그래서 나는 전자 메일 단추가 SMS를 보내고 SMS 단추가 전자 메일을 보내도록 코드를 전환했습니다. 다시 한 번 SMS를 보내야하는 이메일 단추가 응답하지 않습니다. 어떤 아이디어?Android 버튼 오류

import android.app.Activity; 
import android.content.ActivityNotFoundException; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.telephony.SmsManager; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 

public class ContactDaveActivity extends Activity { 


/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


} 

public void buttonhandler(View view) 
{ 
    switch(view.getId()) 
    { 
    case R.id.button1: 
    { 
     try { 
      Intent callIntent = new Intent(Intent.ACTION_CALL); 
      callIntent.setData(Uri.parse("tel:xxxxxxxxxx")); 
      startActivity(callIntent); 
     } 
     catch(ActivityNotFoundException activtyException) 
     { 
      Throwable e = null; 
      Log.e("dialingexample", "Call failed", e); 
     } 
     break; 
    } 
    case R.id.button2: 
    { 
     Intent i = new Intent(Intent.ACTION_SEND); 
     i.setType("text/plain"); 
     String s = "[email protected]"; 
     i.putExtra(Intent.EXTRA_EMAIL, new String[]{s }); 
     startActivity(Intent.createChooser(i, "Send mail...")); 
     break; 

    } 
    case R.id.button3: 
    { 
     String phoneNumber = "+xxxxxxxx"; 
     Intent smsIntent = new Intent(Intent.ACTION_SENDTO); 
     smsIntent.addCategory(Intent.CATEGORY_DEFAULT); 
     smsIntent.setType("vnd.android -dir/mms-sms"); 
     smsIntent.setData(Uri.parse("sms:"+phoneNumber)); 
     startActivity(smsIntent); 
     break; 
    } 

} 

} }

+1

어머. 죄송합니다. main.xml의 android : onClick을 추가하는 것을 잊어 버렸습니다. – QuantumFoam

답변

1

당신이 당신의 main.xml에 파일에 android:onClick="buttonhandler"이?

또한, 모든 단추 1, 단추 2를 확인 단추 3

<Button android:id="@id/button1" android:onClick="buttonhandler" ... /> 

<Button android:id="@id/button2" android:onClick="buttonhandler" ... /> 

<Button android:id="@id/button3" android:onClick="buttonhandler" ... />