AlertDialog中的多个EditText对象 [英] Multiple EditText objects in AlertDialog

查看:196
本文介绍了AlertDialog中的多个EditText对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展大学项目,让用户在地图上放置一个点,然后设置覆盖对象的标题和描述。问题是,第二个 EditText 框将覆盖第一个。这是我的对话框的代码。

I'm working on a project for college that will let a user place a point on a map and then set the title and description for the overlay object. The problem is, the second EditText box overwrites the first one. Here is my code for the dialog box.

//Make new Dialog
AlertDialog.Builder dialog = new AlertDialog.Builder(mapView.getContext());
dialog.setTitle("Set Target Title & Description");
dialog.setMessage("Title: ");

final EditText titleBox = new EditText(mapView.getContext());
dialog.setView(titleBox);

dialog.setMessage("Description: ");
final EditText descriptionBox = new EditText(mapView.getContext());
dialog.setView(descriptionBox);

任何帮助将不胜感激!谢谢!

Any help would be appreciated!! Thanks!

推荐答案

就像任何其他布局一样,您需要将两个EditText添加到ViewGroup中:

Just like any other layout, you need to add both EditTexts to a ViewGroup:

Context context = mapView.getContext();
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);

final EditText titleBox = new EditText(context);
titleBox.setHint("Title");
layout.addView(titleBox);

final EditText descriptionBox = new EditText(context);
descriptionBox.setHint("Description");
layout.addView(descriptionBox);

dialog.setView(layout);

这是一个基本的例子,但它应该让你开始。

This is a basic example, but it should get you started.

这篇关于AlertDialog中的多个EditText对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆