Tag: alertdialog

非活动视图中的AlertDialog框

我正在尝试修改现有应用程序以在View类中包含警报对话框。 如果我在一个活动(另一个应用程序)中运行它,警报对话框工作正常。 但是,当我将它添加到现有应用程序中的View类时,它会失败并显示(无法添加窗口 – 令牌null)错误。 我尝试了“this”(当前View),getContext()和getApplicationContext()。 我读到并非所有的视图都附加到一个活动,因此getContext失败。 有没有其他选择? 我可以使用某种不依赖于活动的通用警报对话框吗? Dialog dialog; final ArrayList itemsSelected = new ArrayList(); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(“Selection:”); builder.setMultiChoiceItems(items.toArray(new String[items.size()]), null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int selectedItemId, boolean isSelected) { if (isSelected) { itemsSelected.add(selectedItemId); } else if (itemsSelected.contains(selectedItemId)) { itemsSelected.remove(Integer.valueOf(selectedItemId)); } } }) .setPositiveButton(“OK”, new DialogInterface.OnClickListener() […]

Android – 显示空ListView的警报对话框

如果没有listview项,如何显示空列表视图的警报对话框。 请找到下面有三个文本字段的图像。 当列表中没有记录/不匹配的记录时,我必须实现空列表视图。 列表视图实现如下: ListView empListView; empListView = (ListView)findViewById(R.id.list1 ); 我必须显示empListView的警告对话框。 请帮我提供样本代码/链接。

具有自定义背景颜色的Android AlertDialog setMultiChoiceItems

我得到了这个alertDialog,有多项选择: builder.setTitle(R.string.layer_options_title) .setMultiChoiceItems(availableOptions, selectedLayerOptions, new DialogInterface.OnMultiChoiceClickListener() { … }); 哪里 availableOptions = getApplicationContext().getResources().getStringArray(R.array.layer_options); 来自 Should have green background Should have yellow background Should have orange background Should have blue background 有没有办法让这些多选项具有背景颜色?

记住单选AlertDialog中选择的内容

我有一个AlertDialog ,它将一个数组显示在一个选定的选项中: protected boolean blFrom, blTo; protected void showSelectToDialog() { boolean[] checkedDate = new boolean[toDate.length]; int count = toDate.length; DialogInterface.OnClickListener setD2 = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //TODO Auto-generated method stub onChangeSelectedTo(which); } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(“Select To Year”); builder.setSingleChoiceItems(toDate, count, setD2); builder.setCancelable(true); builder.setPositiveButton(“Cancel”, new DialogInterface.OnClickListener() […]

Fragment null必须是要从实例状态正确重新创建的公共静态类

当调用getSupportFragmentManager()时,我无法弄清楚为什么我的应用程序崩溃。我在其他应用程序中使用了类似的代码来创建警告对话框而没有任何问题。请帮忙! DialogFragment df = new DialogFragment(){ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.addincome,null); builder.setView(view); //capture final EditText amountEditText=(EditText)view.findViewById(R.id.edit_amount); final EditText descriptionEditText=(EditText)view.findViewById(R.id.edit_description); builder.setNegativeButton(android.R.string.cancel,null); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { newIncome.setAmount(Double.parseDouble(amountEditText.getText().toString())); newIncome.setDescription(descriptionEditText.getText().toString()); user.incomes.add(newIncome); HashMap modified = new HashMap(); modified.put(uid,user); rootref.setValue(modified); } }); […]

Android:更改自定义AlertDialog背景

对话框布局xml: //…content… 点击图钉时,地图叠加中的对话框实现: AlertDialog.Builder builder; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.map_kap_dialog, (ViewGroup) mapView.findViewById(R.id.root_view)); //prepare info to show… //info prepared //other preparations stuff builder = new AlertDialog.Builder(context); builder.setView(layout); dialog = builder.create(); dialog.setInverseBackgroundForced(true); dialog.setCanceledOnTouchOutside(true); //show it dialog.show(); 以及我在测试时看到的内容: 所以我希望对话框周围的浅灰色背景(方形白色空间周围)变为白色,所以看起来不会那么难看。 谁能帮我?

来自线程的警报对话 – Android

我有一个线程,每隔六秒就会将GPS坐标发送到一个数据库,我有一个检查,用于validation用户是否在一个已定义的区域内。 如果用户不在该位置,我想要一个警告对话框,通知他们他们超出范围,如果他们在该区域内,我想要一个告诉他们在范围内的对话框。 我检查工作正常,但我已经尝试过,我很确定我无法在后台线程上添加对话框。 我已经阅读了一些关于使用处理程序的内容,但我不确定如何实现它。 如果您有任何建议我会很感激! 谢谢。 这就是我从主活动( MainActivity.java )调用FindLocation.java : new FindLocation(getBaseContext()).start(usr_id1); //sends a user id with it 下面是FindLocation.java public class FindLocation extends Thread { public boolean inJurisdiction; public boolean AlertNotice = false; private LocationManager locManager; private LocationListener locListener; Context ctx; public String userId; public FindLocation(Context ctx) { this.ctx = ctx; } public void start(String […]

如何在应用程序外部显示AlertDialog框?

@Override public void run() { //Create thread that can alter the UI AlarmPage.this.runOnUiThread(new Runnable() { public void run() { cal = Calendar.getInstance(); //See if current time matches set alarm time if((cal.get(Calendar.HOUR_OF_DAY) == alarmTime.getCurrentHour()) && (cal.get(Calendar.MINUTE) == alarmTime.getCurrentMinute())){ //If the sound is playing, stop it and rewind if(sound.isPlaying()){ ShowDialog(); alarmTimer.cancel(); alarmTask.cancel(); alarmTask = new PlaySoundTask(); alarmTimer […]