为什么在我为电子邮件意图添加代码后,我的 2 个图像按钮停止工作。我一直在摆弄,Public Void onCreate bundle
当我将那部分代码移到下面时,它又可以工作了。我是否错误地嵌套了它们?有人可以纠正吗?
我的 OnClickListener 基本上不起作用,因为单击按钮时什么也不做。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
public class contactActivity extends Activity implements OnClickListener {
private WebView webView;
private WebView webView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
Button mail = (Button)findViewById(R.id.Sendbutton);
mail.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId())
{
case R.id.Sendbutton:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[]{"email add", "",};
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sample mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a sample mail..");
emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send mail client :"));
finish();
break;
}
ImageButton ViewFacebookFeed = (ImageButton) findViewById(R.id.ViewFacebookFeed);
ImageButton ViewTwitterFeed = (ImageButton) findViewById (R.id.ViewTwitterFeed);
//Add a listener to ImageButton1
ViewFacebookFeed.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openBrowser1();
}
});
ViewTwitterFeed.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openBrowser2();
}
});
}
private void openBrowser1()
{
//this intent is used to open other activity which contains another webView
Intent intent = new Intent(contactActivity.this,fbtwitterfeedActivity.class);
startActivity(intent);
}
private void openBrowser2() {
// TODO Auto-generated method stub
Intent intent1 = new Intent(contactActivity.this,twitterfeedActivity.class);
startActivity(intent1);
}
}