Articles of android alertdialog

onClickListener中的AlertDialog

我正在尝试从onClickListener启动AlertDialog但是我收到以下错误。 The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined 有谁知道如何解决这一问题? mRecordButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new AlertDialog.Builder( this ) .setTitle( “Cast Recording” ) .setMessage( “Now recording your message” ) .setPositiveButton( “Save”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d( “AlertDialog”, “Positive” ); } }) .setNegativeButton( “Cancel”, new DialogInterface.OnClickListener() { public void […]

活动生命周期随API 25(7.1.1)而变化

在我的MainActivity中,如果设置了intent中的标志,我会打开一个对话框。 如果对话框已创建,则在onPause()中将其解除 @Override public void onPause() { super.onPause(); if (_dialog!= null) { _dialog.dismiss(); _dialog= null; } } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intentContainsFlag) { _dialog = ….; _dialog.show(); } } 如果按下ListView持有者按钮并构建意图URI,则打开该对话框: bttn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // The URL scheme is registered in the intent filter String intentString […]

Android – 如何使此警报对话框可滚动?

我是android的初学者,并制作我的第一个Android应用程序。 点击后,我的“关于”菜单项会显示一条带有非常长消息的alertdialog。 我一直在尝试不同的方法使其可滚动,但我不能。 我曾尝试在stackoverflow上阅读不同的问题,但它们对我没有用。 这是我的警报对话框代码。 AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle(“Title”); alertDialog.setMessage(“Here is a really long message.”); alertDialog.setButton(“OK”, null); AlertDialog alert = alertDialog.create(); alert.show(); 任何人都可以详细解释我如何使其可滚动? 任何帮助或建议将不胜感激!

如何显示AlertDialog.builder是否正在显示并取消它?

这是我的代码 – View layout = LayoutInflater.from(this).inflate(R.layout.dialog_loc_info, null); final Button mButton_Mobile = (Button) layout.findViewById(R.id.button); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(layout); mButton_Mobile.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if(builder.) showDialog(); // this is another dialog, nothing to do with this code } }); builder.setNeutralButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { […]

如何在Android中的AlertDialog中包含自定义标题视图?

我如何在alertDialog中包含自定义标题栏?我知道android sdk提供了setCustomTitle方法,但它不起作用 编辑: AlertDialog alert = new AlertDialog.Builder(this).setTitle(“Test”).setMessage(“hello”).show(); View view=alert.getLayoutInflater().inflate(R.layout.titlebar, null); alert.setCustomTitle(view); 但上面的代码不起作用 注意:我不是在寻找自定义对话框,而是只想使其标题布局自定义。如下所示

对话框显示时,android非法exception

我有崩溃日志: java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{21f9ba68 VE…. R…..ID 0,0-1136,402} not attached to window manager at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:402) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:328) at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:84) at android.app.Dialog.dismissDialog(Dialog.java:433) at android.app.Dialog.dismiss(Dialog.java:416) at ys.a(ConfirmationDialog.java:82) at ys.a(ConfirmationDialog.java:76) at **com.smarttech.kapp.SnapshotActivity.onOptionsItemSelected(SnapshotActivity.java:147)** at android.app.Activity.onMenuItemSelected(Activity.java:3036) at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:373) at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1222) at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761) at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:155) at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904) at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894) at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:611) at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:197) at android.view.View.performClick(View.java:5217) at android.view.View.onKeyUp(View.java:9663) at android.widget.TextView.onKeyUp(TextView.java:7047) at android.view.KeyEvent.dispatch(KeyEvent.java:3171) at android.view.View.dispatchKeyEvent(View.java:8876) […]

在`Thread.setDefaultUncaughtExceptionHandler`中显示一个对话框

当我的android应用程序抛出exception时,我想显示一个自定义对话框告诉用户发生了错误,所以我使用Thread.setDefaultUncaughtExceptionHandler来设置一个全局exception处理程序: public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, final Throwable ex) { AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); builder.setTitle(“There is something wrong”) .setMessage(“Application will exit:” + ex.toString()) .setPositiveButton(“OK”, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // throw it again […]

将RecyclerView(RecyclerFragment)添加到对话框

我有自定义的RecyclerView来创建ListView。 当我尝试在我的布局id中填充列表视图时,它工作得很好。 FragmentTransaction ft = getFragmentManager().beginTransaction(); Bundle bundle = new Bundle(); bundle.putBoolean(“enablePullToRefresh”, false); GridValues gridValues = new GridValues(); gridValues.rowViewLayout = R.layout.my_detail_row_view; gridValues.delegate = this; mygrid = new CustomGridView(gridValues, bundle); mygrid.showAsGrid = true; mygrid.spanCount = 2; mygrid.layoutOrientation = LinearLayoutManager.VERTICAL; mygrid.noRowColor = true; mygrid.gridName = “mygrid”; mygrid.setArguments(mygrid.bundle); ft.replace(R.id.MyGridContainer, mygrid); 现在,我想在对话框中填充一个新列表。 我怎样才能做到这一点? 我试过这个,让mygrid成为静态的 public static class MyDialogFragment extends […]

Android AlertDialog向左移动PositiveButton,在左侧移动NegativeButton

我是android的新手。 目前我想显示一个带有“确定”和“取消”按钮的AlertDialog框。 默认值为PositiveButton:Left,NegativeButton:Right 你能告诉我怎样才能将PositiveButton移到右侧,将NegativeButton移到左侧? 如果我们将文本“OK”更改为NegativeButton并将“Cancel”更改为PositiveButton,如果Negativebutton在按OK时会导致声音不好,是否有任何机会/麻烦。 我的代码: AlertDialog.Builder builder = new AlertDialog.Builder(SUtils.getContext()); builder.setMessage(“Confirmation?”) .setCancelable(false) .setNegativeButton(“Cancel”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //Todo dialog.cancel(); } }) .setPositiveButton(“OK”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //TOdo } }) dialog = builder.create(); 谢谢,天使

资源$ NotFoundException:AlertDialog中的资源ID#0x0

我有一个RecyclerView ,在其适配器中,我创建了类似于OnLongClickListener东西,我调用OnEntryLongClickListener来避免混淆。 我正在使用AlertDialog来显示包含不同操作的列表项的对话框。 但是,我收到以下错误: E/AndroidRuntime: android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.content.res.Resources.getValue(Resources.java:2345) at android.content.res.Resources.loadXmlResourceParser(Resources.java:3910) at android.content.res.Resources.getLayout(Resources.java:2161) at android.view.LayoutInflater.inflate(LayoutInflater.java:413) at android.view.LayoutInflater.inflate(LayoutInflater.java:366) at android.support.v7.app.AlertController$AlertParams.createListView(AlertController.java:734) at android.support.v7.app.AlertController$AlertParams.apply(AlertController.java:711) at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:883) at com.mycompany.myapp.ThisActivity$2.onEntryLongClick(ThisActivity.java:135) at com.mycompany.myapp.adapter.RVAdapter$RVViewHolder.onLongClick(RVAdapter.java:41) at android.view.View.performLongClick(View.java:5236) 以下是我使用的相关代码: adapter.setOnEntryLongClickListener(new RVAdapter.OnEntryLongClickListener() { @Override public void onEntryLongClick(View view, int position) { final MiniEntry thisEntry = entryList.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext()); builder.setTitle(thisEntry.getEntryName());); builder.setItems(R.array.quickActions, […]