我嘗試將Edittext
和ListView
添加到對話框。 我使用dialog.addContentView(lstcontent,params)
方法將視圖添加到對話框。將內容視圖添加到對話框中
這裏是我的代碼:
dialog = new Dialog(MainActivity.this);
final LinearLayout.LayoutParams lp = new
LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
dialog.addContentView(edittext, lp);
dialog.addContentView(listview,lp);
dialog.show();
,但我的列表視圖是對的EditText。我想在listview上面設置edittext。
我從這個太習慣:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-1, -2);
LinearLayout layout = new LinearLayout(G.context, (AttributeSet) params);
layout.addView(input);
layout.addView(lstcontent);
dialog.setcontentView(layout);
但這種崩潰的應用程序: 的LayoutParams cannout被轉換爲android.util.Attributeset
你爲什麼不從xml.Simply設置你的活動的主題,對話開始使用intent.It將顯示爲dialog.You可以設置視圖太 –