尽管我对 Android 不太了解,但我必须对 Android 应用程序进行一对修复,但我遇到了一些我认为不应该那么困难的问题,我只想要一个 OK 按钮被按下并且某些条件尚未满足,它会显示一条消息并保持在同一屏幕上,直到数据正确或用户取消,但我已经尝试了一段时间,无论我尝试什么,它总是显示消息,然后出现白屏,甚至试图在互联网上搜索示例。
这是我的代码:
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
LinearLayout layout = new LinearLayout(this);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(parms);
layout.setGravity(Gravity.CLIP_VERTICAL);
layout.setPadding(2, 2, 2, 2);
TextView tv = new TextView(this);
tv.setText("Es necesario rellenar los datos solicitados a continuación para poder realizar su primer canje");
tv.setPadding(40, 40, 40, 40);
tv.setGravity(Gravity.CENTER);
tv.setTextSize(20);
EditText et = new EditText(this);
String etStr = et.getText().toString();
TextView tv1 = new TextView(this);
tv1.setText("Nombre completo");
EditText et2 = new EditText(this);
String etStr2 = et2.getText().toString();
TextView tv2 = new TextView(this);
tv2.setText("Teléfono");
final EditText et3 = new EditText(this);
String etStr3 = et3.getText().toString();
TextView tv3 = new TextView(this);
tv3.setText("Correo electrónico");
LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
tv1Params.bottomMargin = 5;
layout.addView(tv1,tv1Params);
layout.addView(et, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
layout.addView(tv2,tv1Params);
layout.addView(et2, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
layout.addView(tv3,tv1Params);
layout.addView(et3, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
alertDialogBuilder.setView(layout);
alertDialogBuilder.setTitle("hola");
// alertDialogBuilder.setMessage("Input Student ID");
alertDialogBuilder.setCustomTitle(tv);
// alertDialogBuilder.setMessage(message);
alertDialogBuilder.setCancelable(true);
// Setting Negative "Cancel" Button
alertDialogBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
alertDialogBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
[more code here]
alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
matcher = pattern.matcher(et3.getText().toString());
if (matcher.matches())
{
[more code here]
}
else
{
Toast.makeText( contexto, "Por favor, introduzca un e-mail válido", Toast.LENGTH_LONG).show();
}
希望你能在这件事上帮助我,因为我觉得必须从一开始就学习 android 才能在 5 分钟或更短的时间内用另一种编程语言完成一些我完全不知道它们的事情,这很烦人。