android builder里面存放两个edittext,android – AlertDialog中的多个EditText对象

对话框只包含一个根视图,这就是setView()覆盖第一个EditText的原因.解决方案很简单,将所有内容放在一个ViewGroup中,例如LinearLayout:

Context context = mapView.getContext();

LinearLayout layout = new LinearLayout(context);

layout.setOrientation(LinearLayout.VERTICAL);

// Add a TextView here for the "Title" label, as noted in the comments

final EditText titleBox = new EditText(context);

titleBox.setHint("Title");

layout.addView(titleBox); // Notice this is an add method

// Add another TextView here for the "Description" label

final EditText descriptionBox = new EditText(context);

descriptionBox.setHint("Description");

layout.addView(descriptionBox); // Another add method

dialog.setView(layout); // Again this is a set method, not add

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

您应该注意set和add方法之间的命名法区别. setView()只保存一个View,对于setMessage()也是如此.事实上,对于每个set方法都应如此,你想到的是添加命令.添加方法是累积的,它们构建了一个列表,列出了所有内容,当set方法是单数时,它们会替换现有数据.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值