我是android新手。我正在开发一个考试应用程序,我想在对话框中显示所有问题编号,以便用户可以切换到任何问题,即1,2,3,4等。我尝试了以下代码,但这是不正确的。我从服务器示例中得到完全没有问题我有40个问题所以我想在对话框中显示1到40之间的数字。请帮忙
AlertDialog.Builder alert = new AlertDialog.Builder(context);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.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.setTextSize(15);
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);
}
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//You will get as string input data in this variable.
// here we convert the input to a string and show in a toast.
String srt = "fdsfdsf";
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();
我已经在这里提出了20个问题,但它可以是任何不。像这样的东西
答案 0 :(得分:1)
似乎你试图显示固定大小的数据,从响应中说出20个数字。简单的方法就是在你的Dialog中设置gridView,并使用固定数量的数据:
GLEW_LOCATION