我有一个EditText输入对话框.当我单击对话框上的"是"按钮时,它将验证输入,然后关闭对话框.但是,如果输入错误,我想保持在同一个对话框中.每次无论输入是什么,当我点击"否"按钮时,对话框应自动关闭.我怎么能禁用它?顺便说一句,我已经使用PositiveButton和NegativeButton作为对话框上的按钮.
android dialog android-alertdialog android-dialog android-dialogfragment
在AlertDialog上的Android文档中,它提供了以下用于在AlertDialog中设置自定义视图的说明和示例:
如果要显示更复杂的视图,请查找名为"body"的FrameLayout并将视图添加到其中:
FrameLayout fl = (FrameLayout) findViewById(R.id.body);
fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)
首先,非常明显的是这add()是一个错字,并且意味着addView().
我对使用R.id.body的第一行感到困惑.它似乎是AlertDialog的body元素......但是我不能在我的代码中输入它b/c它会产生编译错误.R.id.body在哪里被定义或分配或者其他什么?
这是我的代码.我试图setView(findViewById(R.layout.whatever)在构建器上使用但它没有用.我假设因为我没有手动充气吗?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title")
.setCancelable(false)
.setPositiveButton("Go", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
EditText textBox = (EditText) findViewById(R.id.textbox);
doStuff();
}
});
FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an ERROR*/);
f1.addView(findViewById(R.layout.dialog_view));
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud) 目前,当用户打开我的应用程序时,会AlertDialog打开询问他们是否要升级到专业版.我需要添加一个CheckBox,AlertDialog这将使应用程序不再显示AlertDialog用户打开应用程序时.
这就是我AlertDialog现在所拥有的:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(" MY_TEXT");
builder.setMessage(" MY_TEXT ")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Uri uri = Uri.parse("market://details?id=MY_APP_PACKAGE");
Intent intent = new Intent (Intent.ACTION_VIEW, uri);
startActivity(intent); }
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
Run Code Online (Sandbox Code Playgroud)
如果有人能告诉我如何将添加CheckBox到AlertDialog,这将使应用不再显示AlertDialog当用户打开应用程序,这将是巨大的.提前致谢!
我的页面中有一个弹出窗口,其中包含listview.我已经在一个单独的xml中创建了弹出窗口的设计,并在我的主页面上点击了一些按钮.弹出窗口具有列表视图,每行包含图像和文本视图.我无法在android 4.1中的listview中获得行选择,但它在5.0中工作.有人可以建议我解决方案吗?列表显示:
<ListView android:id="@+id/lstSites"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fastScrollEnabled="true"
android:layout_margin="5dp"
android:descendantFocusability="blocksDescendants"></ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
列表视图项目:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:id="@+id/thumbImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/tvSite"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Name"
android:focusable="false"
android:focusableInTouchMode="false"/>
Run Code Online (Sandbox Code Playgroud)
添加行单击列表器:
lstSiteMenu = (ListView) popupView.findViewById(R.id.lstSites);
adapter = new MenuItemsAdapter(SiteActivity.this, arrMenu);
// Attach the adapter to a ListView
lstSiteMenu.setAdapter(adapter);
lstSiteMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
}
Run Code Online (Sandbox Code Playgroud) 我从中获取一些数据FirebaseDatabase然后将它们放入一个array然后尝试List在一个自定义中显示它们AlertDialog.
这是代码:
query = mDatabase.child("child").child(anotherChild).child("yetAnotherChild");
uProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
query.orderByChild("someChild").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot != null) {
Map<String, String> newD = (Map<String, String>) dataSnapshot.getValue();
ArrayList<String> l = new ArrayList<String>();
l.add(newD.get("lol").substring(30));
String names[] = l.toArray(new String[0]);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Activity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.dialog_list, null);
alertDialog.setView(convertView);
alertDialog.setTitle("title");
ListView lv = (ListView) convertView.findViewById(R.id.lv);
ArrayAdapter<String> adapter = …Run Code Online (Sandbox Code Playgroud) android android-arrayadapter android-alertdialog firebase firebase-realtime-database