我使用下面的代碼爲表格佈局的警報對話框設置TextView和EditText。 但我沒有得到在用戶界面。如何設置視圖在Android中的警報對話框中的TextView和EditText?
LinearLayout layout1 = new LinearLayout(SimpleListViewActivity.this);
layout1.setOrientation(LinearLayout.VERTICAL);
final EditText nameEdt = new EditText(this);
final EditText nameEdt1 = new EditText(this);
final EditText nameEdt2 = new EditText(this);
final EditText nameEdt3 = new EditText(this);
LinearLayout.LayoutParams TxtLayoutParams = new LinearLayout.LayoutParams(50,50);
TableRow.LayoutParams rowparams = new TableRow.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(20, 50);
nameEdt.setLayoutParams(new ViewGroup.LayoutParams(20, 20));
nameEdt1.setLayoutParams(new ViewGroup.LayoutParams(20, 20));
nameEdt2.setLayoutParams(new ViewGroup.LayoutParams(20,20));
nameEdt3.setLayoutParams(new ViewGroup.LayoutParams(20, 20));
TextView groupTxt = new TextView(SimpleListViewActivity.this);
groupTxt.setLayoutParams(TxtLayoutParams);
groupTxt.setText("Group");
TextView clientTxt = new TextView(SimpleListViewActivity.this);
clientTxt.setLayoutParams(TxtLayoutParams);
clientTxt.setText("Client");
TextView docTxt = new TextView(SimpleListViewActivity.this);
docTxt.setLayoutParams(TxtLayoutParams);
docTxt.setText("Doc_type");
TextView nameTxt = new TextView(SimpleListViewActivity.this);
nameTxt.setLayoutParams(TxtLayoutParams);
nameTxt.setText("Name");
TableRow grouprow = new TableRow(SimpleListViewActivity.this);
grouprow.setLayoutParams(rowparams);
TableRow clientrow = new TableRow(SimpleListViewActivity.this);
clientrow.setLayoutParams(rowparams);
TableRow docrow = new TableRow(SimpleListViewActivity.this);
docrow.setLayoutParams(rowparams);
TableRow namerow = new TableRow(SimpleListViewActivity.this);
namerow.setLayoutParams(rowparams); // Fixed By Praveen
grouprow.addView(groupTxt);
grouprow.addView(nameEdt3);
clientrow.addView(clientTxt);
clientrow.addView(nameEdt2);
docrow.addView(docTxt);
docrow.addView(nameEdt1);
namerow.addView(nameTxt);
namerow.addView(nameEdt);
layout1.addView(grouprow);
layout1.addView(clientrow);
layout1.addView(docrow);
layout1.addView(namerow);
myDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
System.out.println("Inside Ok");
}
});
myDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
myDialog.setView(layout1);
AlertDialog alertDialog = myDialog.create();
alertDialog.show();
//alertDialog.getWindow().setLayout(200, 800);
}
輸出UI是:
請幫我如何設置視圖?
我想在警報對話框中做....如果我在表格佈局中做..它會很好.. – Baskar 2013-02-11 10:25:27
它可以是任何佈局的事情。不一定是線性或表格 – Neo 2013-02-12 02:12:49