我想調試一些東西,想彈出消息對話框。 Eclipse告訴我它想讓我「創建方法showAlert(string,string,string,boolean)」如何在Android中使用showAlert方法?
我已經導入了這個 import android.content.DialogInterface;
我錯過了哪一步?
我想調試一些東西,想彈出消息對話框。 Eclipse告訴我它想讓我「創建方法showAlert(string,string,string,boolean)」如何在Android中使用showAlert方法?
我已經導入了這個 import android.content.DialogInterface;
我錯過了哪一步?
看起來你可能有一個參數類型不匹配。檢查你的參數實際上是字符串還是布爾值。也許你需要對你的對象打電話toString()
?
如果您嘗試創建並顯示AlertDialog,則應該使用AlertDialog.Builder作爲例子。 DialogInterface,顧名思義,一個接口,只有2種方法:cancel()和dismiss()。
創建AlertDialog相當容易:
new AlertDialog.Builder(this)
.setTitle("Some Title")
.setMessage("some message")
.setPositiveButton("OK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
})
.setNegativeButton("cancel", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when cancel got clicked
}
})
.show();
這顯示了一個簡單AlertDialog。
提示:檢查Activity.showDialog(int)和Activity.onCreateDialog()它們使您在使用對話框時更加輕鬆。
如果只顯示一個調試消息,你可以嘗試Toast.makeText():
Toast.makeText(context, "Hi there!", Toast.LENGTH_SHORT).show();
不要忘記調用show()
。
那麼,我已經走了另一條路......這些是從其他博客幫助頁給出的參數。所以現在我使用的是來自developer.android.com的AlertDialog builder ...已經過去了這個錯誤: [2010-02-01 13:41:12 - MobileServiceCallContacts] ActivityManager:java.lang.SecurityException:Permission Denial :從空(pid = -1,uid = -1)啓動Intent {flg = 0x10000000 cmp = com.msi.ibm.tutorial/.MobileServiceCallContacts}需要android.permission.READ_CONTACTS 並且是的,我將該權限設置爲我的清單...其他地方是否願意去? – jkmcgee 2010-02-01 19:48:18
您應該爲此打開另一個問題......但據我所知,只有在AndroidManifest.xml中需要放置權限 – Justin 2010-02-01 20:47:54