2016-12-01 8 views
0

私は自分のレイアウトをうまくやっていて、残ったいくつかの問題のみを解決しました。私はmailtoとFacebookのリンクボタンを操作することができません。Androidのボタンで問題が発生する

ImageView Button = (ImageView)findViewById(R.id.yourButtonsId); 

Button.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     Intent intent = new Intent(); 
     intent.setAction(Intent.ACTION_VIEW); 
     intent.addCategory(Intent.CATEGORY_BROWSABLE); 
     intent.setData(Uri.parse("http://www.yourURL.com")); 
     startActivity(intent); 
    } 
}); 

TextView textView = (TextView)findViewById(R.id.yourID); 

textView.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     Intent intent = new Intent(); 
     intent.setAction(Intent.ACTION_VIEW); 
     intent.addCategory(Intent.CATEGORY_BROWSABLE); 
     intent.setData(Uri.parse("http://www.typeyourURL.com")); 
     startActivity(intent); 
    } }); 

答えて

0

を、あなたのxmlとメールのボタンでのEditTextを置くよりも、MAILTOを使用したい場合:これは私が試したものです。 ユーザーは自分のメールIDをedittextに追加し、ボタンを押してメールを送信します。送信ボタンをクリックしたときのように書くことができます

Button.setOnClickListener(new OnClickListener() { 
public void onClick(View v) { 

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
    "mailto",yourEditTextObj.getText(), null)); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body"); 
startActivity(Intent.createChooser(emailIntent, "Send email...")); 
} 
}); 
0
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
     "mailto","[email protected]", null)); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body"); 
startActivity(Intent.createChooser(emailIntent, "Send email...")); 
+0

こんにちは、私はこのコードを使用することができますか?私はこれのためだけにXMLをしなければならないのですか?私はmainactivity.xmlで私はアンドロイドを回避する方法を知りません – err0r

+0

onClick()に入れて – ZeroOne

関連する問題