2012-09-03 102 views
0

我試圖建立電子郵件活動,但與當前的代碼鍵我沒有錯誤,但是當我按一下按鈕沒有任何反應上按鈕沒有反應點擊

Email.java

public class Email extends Activity implements View.OnClickListener { 

    EditText personsEmail, intro, personsName, stupidThings, hatefulAction, 
      outro; 
    String emailAdd, beginning, name, stupidAction, hatefulAct, out; 
    Button sendEmail; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.email); 
     initializeVars(); 
     sendEmail.setOnClickListener(this); 
    } 

    private void initializeVars() { 
     // TODO Auto-generated method stub 
     personsEmail = (EditText) findViewById(R.id.etEmails); 
     intro = (EditText) findViewById(R.id.etIntro); 
     personsName = (EditText) findViewById(R.id.etName); 
     stupidThings = (EditText) findViewById(R.id.etThings); 
     hatefulAction = (EditText) findViewById(R.id.etAction); 
     outro = (EditText) findViewById(R.id.etOutro); 
     sendEmail = (Button) findViewById(R.id.bSentEmail); 
    } 

    public void onClick(View v) { 
     // TODO Auto-generated method stub 

     convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated(); 
     String emailaddress[] = { emailAdd }; 
     String message = "Well hello " 
       + name 
       + " I just wanted to say " 
       + beginning 
       + ". Not only that but I hate when you " 
       + stupidAction 
       + ", that just really makes me crazy. I just want to make you " 
       + hatefulAct 
       + ". Welp, thats all I wanted to chit-chatter about, oh and" 
       + out 
       + "Oh and you could visit facebook www.facebook.com/" 
       + '\n' + "PS. I think I love you... "; 

     Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
     emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"I hate you"); 
     emailIntent.setType("Plain/Text"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message); 
     startActivity(emailIntent); 

    } 


    private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() { 
     // TODO Auto-generated method stub 
     emailAdd = personsEmail.getText().toString(); 
     beginning = intro.getText().toString(); 
     name = personsName.getText().toString(); 
     stupidAction = stupidThings.getText().toString(); 
     hatefulAct = hatefulAction.getText().toString(); 
     out = outro.getText().toString(); 
    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
     finish(); 
    }  
} 

Menu.java

public class Menu extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //Setting Up Button 

     Button but1 =(Button) findViewById(R.id.bEmail); 

     but1.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       startActivity(new Intent("com.guess.guessme.EMAIL")); 
      } 
     }); 

    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
    }  
} 
+1

試圖給這條線 - 'sendEmail.setOnClickListener(本);'你的方法裏面'initializeVars()' – Praveenkumar

+3

和你的問題是... – mKorbel

+0

@mKorbel我已經設置了整個佈局,一切都完成了,但是當我點擊'電子郵件我'按鈕時我沒有任何反應,它導致我無處可尋 –

回答

0

試圖改變自己從emailIntent.setType("Plain/Text");emailIntent.setType("text/html"); 並進行以下更改可能會幫助你

startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
0

試試這個:

startActivity(new Intent("com.guess.guessme.Email")); 

並確保,電子郵件活動在您的清單文件規定了。

+0

我也試過了!不工作,是的,顯然我在Manifest –

+0

交叉檢查哦,試試這個:'startActivity(new Intent(this,com.guess.guessme.Email.class))'。這是因爲對於您使用的Intent構造函數,字符串參數不是活動類的名稱,而是一個Action,您必須在Manifest中指定等。爲了調用您自己的項目的活動,建議的方法很多簡單。 – Ridcully

0

嘗試

emailIntent.setType("message/rfc822"); 
Email.this.startActivity(Intent.createChooser(email, "Choose an Email client :"); 
0

嘗試做這樣的 -

看來你正在實施錯了聽衆。試試導入OnClickListener而不是View.OnClickListener像下面 -

public class Email extends Activity implements OnClickListener 

與下面的代碼。

+0

@Lakshay Narula還有一件事?你在你的設備或模擬器中嘗試這個嗎? – Praveenkumar

+0

我首先在我的DEVICE上嘗試導致其電子郵件活動,然後在設備上它不工作,然後在模擬器上。我的第一個項目有EXACT相同的編碼,並在設備上正常工作 –

+0

@LakshayNarula其實,哪一個不工作。你不能重定向到'Email.java'類嗎? – Praveenkumar

1

您可以使用此代碼。它可能會解決你的問題: startActivity(new Intent(Menu.this, Email .class));

+0

未發生配對:( –