如何在对话框中添加多个文本视图
How to add multiple textviews in dialog box
我想在对话框中添加多个 TextView。我试过了,但它只显示一个 TextView。
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Alert Dialog With EditText"); //Set Alert dialog title here
alert.setMessage("Enter Your Name Here"); //Message here
for (int i =0; i<20; i++) {
// Set an EditText view to get user input
final TextView input = new TextView(context);
input.setText("" + i);
input.setPadding(5, 5, 5, 5);
input.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String srt = "clickd";
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
}
});
alert.setView(input);
}
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String srt = "Dialogg";
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
} // End of onClick(DialogInterface dialog, int whichButton)
}); //End of alert.setPositiveButton
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
}); //End of alert.setNegativeButton
AlertDialog alertDialog = alert.create();
alertDialog.show();
我想在对话框中显示从 1 到 20 的数字。请帮助我如何做到这一点。
我要做的是创建一个线性布局,然后将文本视图添加到线性布局,然后将线性布局添加到对话框。
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
for (int i =0; i<20; i++) {
// Set an EditText view to get user input
final TextView input = new TextView(context);
input.setText("" + i);
input.setPadding(5, 5, 5, 5);
input.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String srt = "clickd";
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
}
});
layout.addView(input);
然后
alert.setView(layout);
您可以使用自定义警报对话框。使用这种方法,您将更好地控制警报对话框:
http://www.mkyong.com/android/android-custom-dialog-example/
我想在对话框中添加多个 TextView。我试过了,但它只显示一个 TextView。
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Alert Dialog With EditText"); //Set Alert dialog title here
alert.setMessage("Enter Your Name Here"); //Message here
for (int i =0; i<20; i++) {
// Set an EditText view to get user input
final TextView input = new TextView(context);
input.setText("" + i);
input.setPadding(5, 5, 5, 5);
input.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String srt = "clickd";
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
}
});
alert.setView(input);
}
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String srt = "Dialogg";
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
} // End of onClick(DialogInterface dialog, int whichButton)
}); //End of alert.setPositiveButton
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
}); //End of alert.setNegativeButton
AlertDialog alertDialog = alert.create();
alertDialog.show();
我想在对话框中显示从 1 到 20 的数字。请帮助我如何做到这一点。
我要做的是创建一个线性布局,然后将文本视图添加到线性布局,然后将线性布局添加到对话框。
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
for (int i =0; i<20; i++) {
// Set an EditText view to get user input
final TextView input = new TextView(context);
input.setText("" + i);
input.setPadding(5, 5, 5, 5);
input.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String srt = "clickd";
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
}
});
layout.addView(input);
然后
alert.setView(layout);
您可以使用自定义警报对话框。使用这种方法,您将更好地控制警报对话框:
http://www.mkyong.com/android/android-custom-dialog-example/