如何在对话框中显示edittext和listview以及正负按钮?我试图分开展示它们,但我希望所有这些都在一个对话框中。
要显示我尝试的编辑文字:
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setView(modeList);
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String myTextString = savedText.getText().toString().trim();
}
});
答案 0 :(得分:3)
答案 1 :(得分:1)
制作新的布局文件并:
public void showYourCustomDialog(){
this.showDialog(YOUR_CUSTOM_DIALOG_ID);
}
@Override
public Dialog onCreateDialog(int id){
if(id == YOUR_CUSTOM_DIALOG_ID){
Dialog d = new Dialog();
d.setContentView(R.id.your_dialog_layout);
// maybe more things
return d;
} else return super.onCreateDialog(id);
}
您也可以创建一个新的类文件并扩展Dialog类。然后,您可以在对话框中添加新用途,而不是Android提供的基础知识。
答案 2 :(得分:0)
试试这个:
String[] p_values = populate_the_list_with_your_content();
ListView mListview = new ListView(this); // pass your context here
adpter = new ArrayAdapter<String>(this,R.layout.your_raw_item_with_whatever_you_like, p_values);
mListview.setAdapter(adpter);
AlertDialog mAlertDialog;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
AlertDialog.Builder mBuider = new AlertDialog.Builder(your_context);
mBuider.setTitle("title"); // optional
mBuider.setPositiveButton("positive", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do what you got to do - just be positive
}
});
mBuider.setNegativeButton("Back",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// negative reaction
}
});
mBuider.setView(mListview);
mAlertDialog = mBuider.create();
lp.copyFrom(mAlertDialog.getWindow().getAttributes());
mAlertDialog.show();
适合我。的nJoy!