[英]Get context and activity (no null) on Fragment inside a setOnCLickListener
[英]Proper way to get context of parent activity inside fragment fragment
我正在開發小型Android應用程序,在我的應用程序中我使用片段概念。 在我的一個活動中,我使用多個片段並進行這些片段的轉換。 現在在一個片段中我顯示一個警告對話框,因為我需要傳遞活動的上下文。 我是用以下方式做到的。
new AlertDialog.Builder(getSherlockActivity())
.setTitle("Logout")
.setMessage("Really Logout from App?")
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
}).setNegativeButton("No", null).show();
一切都工作正常,沒有任何錯誤,沒有任何失敗。 只有一個問題是在logcat中它向我顯示我的主要活動已經泄露了意圖。 這是問題所在; 是這個問題因為我正在傳遞getsherlockActivity();
還是因為別的什么? 想澄清這個概念......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.