我在LG Eve手机上测试我的应用程序.我有一个应用程序试图从Web下载一些东西,当它抛出一个异常时,它应该启动一个alertdialog说有一个错误.当手机没有wifi信号时,程序会在builder.create()崩溃(见下面的代码).但是,当有wifi信号,并且异常被其他东西抛出时(例如,url中的拼写错误),对话框将启动它应该的方式.任何线索,为什么这可能是?
onCreateDialog的代码:
@Override
protected Dialog onCreateDialog(int id){
Dialog d = null;
switch (id){
case DIALOG_DATA_ERROR_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getResources().getString(R.string.error_data));
builder.setCancelable(false);
builder.setNeutralButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface d, int id){
d.cancel();
}
});
d = builder.create();
break;
}
return d;
}
Run Code Online (Sandbox Code Playgroud)
调用showDialog的AsyncTask代码:
private static class DownloadJSONTask extends AsyncTask<String, Void, String>{
private ProgressDialog dialog;
private Activity parent;
private JSONParserInterface jsonParser;
public DownloadJSONTask(Activity parent, JSONParserInterface jsonParser){
this.parent = parent;
this.jsonParser = jsonParser;
}
protected void onPreExecute(){
dialog = ProgressDialog.show(parent, "Loading", …Run Code Online (Sandbox Code Playgroud) 当我使用带有listadapter的AlertDialog.Builder的setSingleChoiceItems时,单选按钮不显示.如果我使用Charsequence []数组,单选按钮会显示.请看一下我正在使用的代码.提前致谢!!
公共类ExampleApp扩展Activity {
Context mContext;
ListAdapter myListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
myListAdapter = new myListAdapter(mContext);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setTitle("Select any icon");
alt_bld.setSingleChoiceItems(myListAdapter, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), "Selected icon = "+imageName[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = alt_bld.create();
alert.show();
}
private class myListAdapter extends BaseAdapter{
public myListAdapter(Context mContext){
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return imageName.length;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我似乎遇到了创建AlertDialog的问题.我想要做的是创建一个自定义AlertDialog,当单击一个特定的RadioButton时弹出.这是我的相关代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_Minutes = -1;
m_this=this;
String prefName = getString(R.string.prefsfile);
SharedPreferences settings = getSharedPreferences(prefName, 0);
String defaultTextBackMessage = settings.getString("textBackMessage", getString(R.string.defaultTextBackMessage));
EditText txtMessage = (EditText)findViewById(R.id.editText1);
txtMessage.setText(defaultTextBackMessage);
final Button button = (Button)findViewById(R.id.button1);
final RadioButton manualButton = (RadioButton)findViewById(R.id.radio0);
final RadioButton button15 = (RadioButton)findViewById(R.id.radio1);
final RadioButton button30 = (RadioButton)findViewById(R.id.radio2);
final RadioButton customButton = (RadioButton)findViewById(R.id.radio3);
manualButton.setChecked(true);
customButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context c = v.getContext();
LayoutInflater factory = LayoutInflater.from(v.getContext());
final View minuteEntryView = factory.inflate(R.layout.customtime, null); …Run Code Online (Sandbox Code Playgroud) 我相信我以前见过这样的问题,但我无法在任何地方找到它...所以,我会发布我的问题版本,除非别人知道它的链接.
无论如何...
我有一个AlertDialog在我的strings.xml文件中显示一个字符串以显示在对话框中.字符串看起来像这样:
<string name="about_app">
Blah blah blah talking about stuff this is a line
Oh look I continued onto another line! Now I want these...\n\n
So this is another paragraph! Intriguing. Yes, onto the next line
Android text doesn't necessarily consider this a new line, which is fine
becauase i only care about paragraphs, which I'm using backslash n's for!\n\n
And... here's my final statement! Woo.\n
</string>
Run Code Online (Sandbox Code Playgroud)
一切都在AlertDialog中正确显示(有些)."Blah blah blah ......"与它的左边缘对齐AlertDialog并继续直到它击中\n\n.从这里,我得到了我想要的间距"所以这是......".然而,"所以这就是......"缩进了一个令人讨厌的小空间,我无法摆脱它!同样的"而且......这是我的......".有人有解决方案吗? …
我正在尝试开发一个应用程序,你会说出一个名字,它会查找你的联系人并返回所有名字,如"Lars A.,Lars B.,Lars C.".我将所有这些名称保存在ArrayList中并且它可以正常工作.现在我想要一个AlertDialog,因此用户可以从此列表中选择正确的联系人.我想出来,它必须是一个CharSequence,所以我之前转换它.但我认为列表是空的,因为我只看到警报消息.
这个网站描述得很好,但使用静态值,我需要动态值:Android Developer Site.
继承我的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
CharSequence[] cs = namearray.toArray(new CharSequence[namearray.size()]);
builder.setMessage("Welche/n " + cname + " meinst du?");
builder.setItems(cs, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int item) {
//do something
} });
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud) 在这个方法中,我曾经调用AlertDialog Box.但是当我调用警报对话框时.我总是得到胎儿异常.以下是我在警报Dialog Builder中收到的错误.请帮我找.
12-18 04:25:10.222: E/AndroidRuntime(4173): FATAL EXCEPTION: main
12-18 04:25:10.222: E/AndroidRuntime(4173): Process: com.androidexample.customlistview, PID: 4173
12-18 04:25:10.222: E/AndroidRuntime(4173): java.lang.NullPointerException
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.app.AlertDialog.resolveDialogTheme (AlertDialog.java:143)
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
12-18 04:25:10.222: E/AndroidRuntime(4173): at com.androidexample.customlistview.CustomListViewAndroidExample.updateData (CustomListViewAndroidExample.java:162)
12-18 04:25:10.222: E/AndroidRuntime(4173): at com.androidexample.customlistview.CustomAdapter$1.onClick(CustomAdapter.java:144)
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.view.View.performClick(View.java:4424)
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.view.View$PerformClick.run(View.java:18383)
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.os.Handler.handleCallback(Handler.java:733)
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.os.Handler.dispatchMessage(Handler.java:95)
12-18 04:25:10.222: E/AndroidRuntime(4173): at android.os.Looper.loop(Looper.java:137) 12-18 04:25:10.222: E/AndroidRuntime(4173): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-18 04:25:10.222: E/AndroidRuntime(4173): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 04:25:10.222: …Run Code Online (Sandbox Code Playgroud) 我正在尝试向警报对话框添加边框。我希望使其看起来像这样:

到目前为止,我发现的最佳解决方案是使用可绘制的九个补丁作为对话框的背景。
问题是我还没有找到一种方法来制作九个补丁背景,而实际上却为对话框周围提供了一条一致的白线。到目前为止,这是我最好的尝试(对不起,有点难以理解...):

问题是,这会产生如下所示的对话框:

这里的问题是双重的。两侧的线太粗了,顶部的线因阴影而褪色。
我唯一的想法是找到一个工作九个补丁来提供一致的粗边框,或者找到一种方法来获取警报对话框的“主布局”,因此我可以直接在其中添加填充。
像这样在“警报”对话框上设置边框的最佳方法是什么?
我最近发布了关于MultiSpinner值的问题,以从微调器对话框中选择多个值。我已经成功完成了下课。
MultiSpinnerSearch.java
package com.example.multiplechoicelistwithfilter;
import java.util.List;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
public class MultiSpinnerSearch extends Spinner implements OnCancelListener {
private List<Hello> items;
//private boolean[] selected;
private String defaultText;
private MultiSpinnerListener listener;
public MultiSpinnerSearch(Context context) {
super(context);
}
public MultiSpinnerSearch(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
}
public MultiSpinnerSearch(Context arg0, AttributeSet arg1, int arg2) …Run Code Online (Sandbox Code Playgroud) android android-listview android-alertdialog android-filter android-filterable
我正在设计一个弹出AlertDialog,它将警报对话框的视图设置为以下XML文件.由于某种原因,文件不会添加边距,我无法弄清楚我做错了什么.边距和填充不适用于activity_priority_level_values LinearLayout,包含所有TextView的LinearLayout或任何TextView.如何为所有文本视图之间的对话框边框和边距添加边距(或填充)?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_priority_level_values"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/large_space">
<TextView android:id="@+id/level_1_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_1_header"/>
<TextView android:id="@+id/level_1_decription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_1_description"/>
<TextView android:id="@+id/level_2_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_2_header"/>
<TextView android:id="@+id/level_2_decription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/mid_space"
android:text="@string/level_2_description"/>
<TextView android:id="@+id/level_3_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_3_header"/>
<TextView android:id="@+id/level_3_decription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/mid_space"
android:text="@string/level_3_description"/>
<TextView android:id="@+id/level_4_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_4_header"/>
<TextView android:id="@+id/level_4_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/mid_space"
android:text="@string/level_4_description"/>
<TextView android:id="@+id/level_5_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_5_header"/>
<TextView android:id="@+id/level_5_decription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level_5_description"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
活动
LinearLayout hiddenLayout = (LinearLayout)findViewById(R.id.activity_priority_level_values);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
if(hiddenLayout == null){ …Run Code Online (Sandbox Code Playgroud) 我在基于Lollipop的android手机以及基于Jellybean的android手机上都能完美运行同一应用程序。但是,警报对话框的样式(默认)并不相同,并且该对话框在Lollipop手机中显得难看。
一个简单的例子:
在基于豆形软糖的电话中:
在基于棒棒糖的手机中:
我可以在基于Lollipop的手机上使用旧版Android OS的警报对话框样式吗?
如何在应用中以编程方式执行此操作?
android android-alertdialog android-4.2-jelly-bean android-5.0-lollipop