爲我的電子郵件意圖添加代碼後,爲什麼我的2圖像按鈕停止工作。我一直在擺弄Public Void onCreate bundle
,當我移動下面的代碼段時,它再次起作用。我把它們錯誤地嵌套了嗎?有人可以糾正它嗎?爲什麼我的2個按鈕停止工作?
我的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);
}
}
你怎麼知道「onClickListeners不工作」處理所有的點擊? – Simon
你的OnClickListener被調用了嗎?你可以在那裏寫一條日誌語句來驗證? – CaseyB
@CaseyB爲什麼要添加代碼?爲什麼不只是一個斷點? – Simon