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方法是單數時,它們會替換現有數據.
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的android builder里面存放两个edittext,android – AlertDialog中的多个EditText对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android本地存储键值对,flutt
- 下一篇: android压缩图片不失真,Andro