日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android 点击对话框按钮 不关闭按钮,Android在单击PositiveButton后不要关闭AlertDialog...

發布時間:2023/12/18 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 点击对话框按钮 不关闭按钮,Android在单击PositiveButton后不要关闭AlertDialog... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android在單擊PositiveButton后不要關閉AlertDialog

我可以在單擊PositiveButton之后不關閉我的AlertDialog嗎?

我想保留對話框以在ArrayAdapter listWords上顯示一些更新。

這是我的代碼。

AlertDialog.Builder sayWindows = new AlertDialog.Builder(MapActivity.this);

final EditText saySomething = new EditText(MapActivity.this);

sayWindows.setPositiveButton("ok",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

say = userName + " Says: "+saySomething.getText();

showPosition.setText(say);

}

});

sayWindows.setNegativeButton("cancel",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}

});

sayWindows.setAdapter(listWords, null);

sayWindows.setView(saySomething);

sayWindows.create().show();

5個解決方案

65 votes

看完@Little Child解決方案后,我嘗試做這個。 讓我們知道這是否適合您。

AlertDialog.Builder sayWindows = new AlertDialog.Builder(

MapActivity.this);

final EditText saySomething = new EditText(MapActivity.this);

sayWindows.setPositiveButton("ok", null);

sayWindows.setNegativeButton("cancel", null);

sayWindows.setAdapter(listWords, null);

sayWindows.setView(saySomething);

final AlertDialog mAlertDialog = sayWindows.create();

mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

@Override

public void onShow(DialogInterface dialog) {

Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// TODO Do something

say = userName + " Says: "+saySomething.getText();

showPosition.setText(say);

}

});

}

});

mAlertDialog.show();

Chitrang answered 2020-08-11T04:26:26Z

13 votes

基于有關如何防止單擊按鈕時關閉對話框的投票最多的答案

final AlertDialog d = new AlertDialog.Builder(context)

.setView(v)

.setTitle(R.string.my_title)

.setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick

.setNegativeButton(android.R.string.cancel, null)

.create();

d.setOnShowListener(new DialogInterface.OnShowListener() {

@Override

public void onShow(DialogInterface dialog) {

Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// TODO Do something

}

});

}

});

我相信您需要覆蓋肯定按鈕的處理程序。 添加您的邏輯以在滿足特定條件時關閉對話框。

Little Child answered 2020-08-11T04:26:50Z

10 votes

更簡單:

final AlertDialog alertDialog = new AlertDialog.Builder(context).setView(v)

.setPositiveButton(android.R.string.ok, null)

.setNegativeButton(android.R.string.cancel, null)

.show();

Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

//Do Your thing

}

});

M. Usman Khan answered 2020-08-11T04:27:10Z

5 votes

在科特林回答:

val dialog = AlertDialog.Builder(context)

.setView(v)

.setTitle(R.string.my_title)

.setPositiveButton(android.R.string.ok, null)

.setNegativeButton(android.R.string.cancel, null)

.create()

dialog.setOnShowListener {

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {

// Apply logic here

}

}

Steve Lukis answered 2020-08-11T04:27:30Z

4 votes

我這樣做是這樣的:

final AlertDialog dialog = new AlertDialog.Builder(this)

.setCancelable(false)

.setPositiveButton("YES", null)

.setNegativeButton("NO", null)

.show();

Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);

positiveButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Toast.makeText(SysManagerActivity.this, "dialog is open", Toast.LENGTH_SHORT).show();

}

});

Yury Matatov answered 2020-08-11T04:27:50Z

總結

以上是生活随笔為你收集整理的android 点击对话框按钮 不关闭按钮,Android在单击PositiveButton后不要关闭AlertDialog...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。