日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發布時間:2023/12/18 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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...的全部內容,希望文章能夠幫你解決所遇到的問題。

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