中顯示來自listview按鈕的提醒確認對話框我試圖在點擊列表視圖中的按鈕之後顯示確認對話框。如何在android
我在getView方法setOnClickListener我CustomAdapter。
但點擊收聽我收到以下錯誤:
02-25 21:36:32.065 20631-20631/com.themsg.chat W/Toast: From com.themsg.chat, go ahead.
02-25 21:36:32.095 20631-20631/com.themsg.chat W/System.err: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
02-25 21:36:32.095 20631-20631/com.themsg.chat W/System.err: at android.view.ViewRootImpl.setView(ViewRootImpl.java:569)
02-25 21:36:32.095 20631-20631/com.themsg.chat W/System.err: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:266)
02-25 21:36:32.095 20631-20631/com.themsg.chat W/System.err: at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
02-25 21:36:32.095 20631-20631/com.themsg.chat W/System.err: at android.app.Dialog.show(Dialog.java:286)
這裏是我的代碼:
holder.tvm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
chatroomMembers = getItem(position);
Toast.makeText(getContext(), "here", Toast.LENGTH_LONG).show();
new AlertDialog.Builder(v.getContext())
.setTitle("Title")
.setMessage("Do you really want to whatever?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
deleteUserFromChatrrom(chatroomMembers.getId(), SessionData.getInstance().getCurrentChatroom(), position);
}})
.setNegativeButton(android.R.string.no, null).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
爲什麼你沒有得到錯誤'方法getContext()是未定義的類型新View.OnClickListener(){}'在你的吐司行... – Mohit
我的意思是你沒有方法'getContext()'在'View.OnClickListener()' – Mohit