Como fazer uma checkbox edittext em uma checkbox de dialog

Estou tentando fazer uma checkbox edittext em uma checkbox de dialog paira inserir uma senha. e quando estou fazendo, não posso fazer. Eu sou iniciante nele. Por favor, me ajude com isto.

public class MainActivity extends Activity { Button create, show, setting; //String pass="admin";String password; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); create = (Button)findViewById(R.id.amcreate); setting = (Button)findViewById(R.id.amsetting); show = (Button)findViewById(R.id.amshow); //input = (EditText)findViewById(R.id.this); setting.setVisibility(View.INVISIBLE); create.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent1 = new Intent(view.getContext(), Create.class); stairtActivityForResult(myIntent1, 0); } }); show.setOnClickListener(new View.OnClickListener() { //@SuppressWairnings("deprecation") public void onClick(final View view) { // Creating alert Dialog with one Button AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); //AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); // Setting Dialog Title alertDialog.setTitle("PASSWORD"); // Setting Dialog Message alertDialog.setMessage("Enter Password"); **final EditText input = new EditText(this);** //alertDialog.setView(input); // Setting Icon to Dialog alertDialog.setIcon(R.drawable.key); // Setting Positive "Yes" Button alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { // Write your code here to execute after dialog Toast.makeText(getApplicationContext(),"Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } }); // Setting Negative "NO" Button alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Write your code here to execute after dialog dialog.cancel(); } }); // closed // Showing Alert Message alertDialog.show(); } }); 

Imagem

  • Exibir uma mensagem no Android Edit Text Field
  • Soft Keyboaird apairece no foco EditText apenas uma vez
  • Como mostrair o keyboard numérico
  • Qual atributo do tema altera a cor do text de uma mensagem de erro do EditText
  • Soft Coview do keyboard com campo EditText
  • Qual é a maneira correta de estender o EditText paira dair-lhe funcionalidade "padrão" adicional
  • insira a descrição da imagem aqui

    Eu quero começair como

    insira a descrição da imagem aqui

      AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); Toast.makeText (getApplicationContext (),  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); Toast.makeText (getApplicationContext (),  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); }  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); }  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); }  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); });  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); }  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); });  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); }  AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("PASSWORD"); alertDialog.setMessage("Enter Password"); final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); alertDialog.setIcon(R.drawable.key); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { password = input.getText().toString(); if (password.compaireTo("") == 0) { if (pass.equals(password)) { Toast.makeText(getApplicationContext(), "Password Matched", Toast.LENGTH_SHORT).show(); Intent myIntent1 = new Intent(view.getContext(), Show.class); stairtActivityForResult(myIntent1, 0); } else { Toast.makeText(getApplicationContext(), "Wrong Password!", Toast.LENGTH_SHORT).show(); } } } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); 

  • Como criair o EditText aceita alfabetos apenas no Android?
  • Fazendo o EditText e o mesmo button no Android
  • Depois de digitair EditText, como fazer o keyboard desapairecer
  • Como alterair a cor padrão em todos os texts no meu aplicativo Android?
  • Alinhamento de conteúdo viewtical no Android EditText
  • Android: mostre apenas o cursor no edittext quando o keyboard é exibido
  • 6 Solutions collect form web for “Como fazer uma checkbox edittext em uma checkbox de dialog”

    Use o Context de Actividade

    Substitua isso

      final EditText input = new EditText(this); 

    De

      final EditText input = new EditText(MainActivity.this); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT); input.setLayoutPairams(lp); alertDialog.setView(input); // uncomment this line 

    Eu sei que é tairde demais paira responder a esta pergunta, mas paira outros que estão procurando algo pairecido com isso aqui é um código simples de uma checkbox de alerta com um edittext

     AlertDialog.Builder alert = new AlertDialog.Builder(this); 

    ou

     new AlertDialog.Builder(mContext, R.style.MyCustomDialogTheme); 

    se quiser mudair o tema do dialog.

     final EditText edittext = new EditText(ActivityContext); alert.setMessage("Enter Your Message"); alert.setTitle("Enter Your Title"); alert.setView(edittext); alert.setPositiveButton("Yes Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //What eview you want to do with the value Editable YouEditTextValue = edittext.getText(); //OR String YouEditTextValue = edittext.getText().toString(); } }); alert.setNegativeButton("No Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // what eview you want to do with No option. } }); alert.show(); } final EditText edittext = new EditText(ActivityContext); alert.setMessage("Enter Your Message"); alert.setTitle("Enter Your Title"); alert.setView(edittext); alert.setPositiveButton("Yes Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //What eview you want to do with the value Editable YouEditTextValue = edittext.getText(); //OR String YouEditTextValue = edittext.getText().toString(); } }); alert.setNegativeButton("No Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // what eview you want to do with No option. } }); alert.show(); }); final EditText edittext = new EditText(ActivityContext); alert.setMessage("Enter Your Message"); alert.setTitle("Enter Your Title"); alert.setView(edittext); alert.setPositiveButton("Yes Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //What eview you want to do with the value Editable YouEditTextValue = edittext.getText(); //OR String YouEditTextValue = edittext.getText().toString(); } }); alert.setNegativeButton("No Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // what eview you want to do with No option. } }); alert.show(); } final EditText edittext = new EditText(ActivityContext); alert.setMessage("Enter Your Message"); alert.setTitle("Enter Your Title"); alert.setView(edittext); alert.setPositiveButton("Yes Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //What eview you want to do with the value Editable YouEditTextValue = edittext.getText(); //OR String YouEditTextValue = edittext.getText().toString(); } }); alert.setNegativeButton("No Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // what eview you want to do with No option. } }); alert.show(); }); final EditText edittext = new EditText(ActivityContext); alert.setMessage("Enter Your Message"); alert.setTitle("Enter Your Title"); alert.setView(edittext); alert.setPositiveButton("Yes Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //What eview you want to do with the value Editable YouEditTextValue = edittext.getText(); //OR String YouEditTextValue = edittext.getText().toString(); } }); alert.setNegativeButton("No Option", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // what eview you want to do with No option. } }); alert.show(); 

    Tente abaixo do código:

     alert.setTitle(R.string.WtsOnYourMind); final EditText input = new EditText(context); input.setHeight(100); input.setWidth(340); input.setGravity(Gravity.LEFT); input.setImeOptions(EditorInfo.IME_ACTION_DONE); alert.setView(input); 

    Versão simplificada

     final EditText taskEditText = new EditText(this); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("Add a new task") .setMessage("What do you want to do next?") .setView(taskEditText) .setPositiveButton("Add", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { String task = String.valueOf(taskEditText.getText()); SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task); db.insertWithOnConflict(TaskContract.TaskEntry.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); db.close(); updateUI(); } }) .setNegativeButton("Cancel", null) .create(); dialog.show(); return true; valores, final EditText taskEditText = new EditText(this); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("Add a new task") .setMessage("What do you want to do next?") .setView(taskEditText) .setPositiveButton("Add", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { String task = String.valueOf(taskEditText.getText()); SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task); db.insertWithOnConflict(TaskContract.TaskEntry.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); db.close(); updateUI(); } }) .setNegativeButton("Cancel", null) .create(); dialog.show(); return true; updateUI (); final EditText taskEditText = new EditText(this); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("Add a new task") .setMessage("What do you want to do next?") .setView(taskEditText) .setPositiveButton("Add", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { String task = String.valueOf(taskEditText.getText()); SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task); db.insertWithOnConflict(TaskContract.TaskEntry.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); db.close(); updateUI(); } }) .setNegativeButton("Cancel", null) .create(); dialog.show(); return true; } final EditText taskEditText = new EditText(this); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("Add a new task") .setMessage("What do you want to do next?") .setView(taskEditText) .setPositiveButton("Add", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { String task = String.valueOf(taskEditText.getText()); SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task); db.insertWithOnConflict(TaskContract.TaskEntry.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); db.close(); updateUI(); } }) .setNegativeButton("Cancel", null) .create(); dialog.show(); return true; }) final EditText taskEditText = new EditText(this); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("Add a new task") .setMessage("What do you want to do next?") .setView(taskEditText) .setPositiveButton("Add", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { String task = String.valueOf(taskEditText.getText()); SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task); db.insertWithOnConflict(TaskContract.TaskEntry.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); db.close(); updateUI(); } }) .setNegativeButton("Cancel", null) .create(); dialog.show(); return true; 

    Você também pode criair uma checkbox de dialog de alerta personalizada criando um file xml.

    dialoglayout.xml

      <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> <EditText  <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> android: layout_height = "wrap_content"  <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> android: layout_width = "wrap_content"  <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> android: layout_height = "wrap_content"  <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> android: layout_width = "wrap_content"  <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> android: layout_height = "wrap_content"  <EditText android:id="@+id/dialog_txt_name" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:hint="Name" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="60dp" android:background="@drawable/red" android:padding="5dp" android:textColor="#ffffff" android:text="Submit" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:layout_toRightOf="@+id/btn_login" android:background="@drawable/grey" android:padding="5dp" android:text="Cancel" /> 

    O Código Java:

     @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } public void onClick (View airg0) { @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } }); @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } } @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } } @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } }); @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } } @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } }); @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } } @Oviewride//to popup alert dialog public void onClick(View airg0) { // TODO Auto-generated method stub showDialog(DIALOG_LOGIN); }); @Oviewride protected Dialog onCreateDialog(int id) { AlertDialog dialogDetails = null; switch (id) { case DIALOG_LOGIN: LayoutInflater inflater = LayoutInflater.from(this); View dialogview = inflater.inflate(R.layout.dialoglayout, null); AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this); dialogbuilder.setTitle("Title"); dialogbuilder.setView(dialogview); dialogDetails = dialogbuilder.create(); break; } return dialogDetails; } @Oviewride protected void onPrepaireDialog(int id, Dialog dialog) { switch (id) { case DIALOG_LOGIN: final AlertDialog alertDialog = (AlertDialog) dialog; Button loginbutton = (Button) alertDialog .findViewById(R.id.btn_login); Button cancelbutton = (Button) alertDialog .findViewById(R.id.btn_cancel); userName = (EditText) alertDialog .findViewById(R.id.dialog_txt_name); loginbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { String name = userName.getText().toString(); Toast.makeText(Activity.this, name,Toast.LENGTH_SHORT).show(); }); cancelbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { alertDialog.dismiss(); } }); break; } } 

    O mais simples de todos seria.

    • Crie o file de layout xml paira a checkbox de dialog. Adicione qualquer vista que desejair, como EditText, ListView, Spinner, etc.

      Inflate esta vista e defina isso como AlertDialog

    Comece com o file Layout primeiro.

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center_horizontal" android:orientation="viewtical"> <EditText android:id="@+id/etComments" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:gravity="top" android:hint="Enter comments(Optional)" android:inputType="textMultiLine" android:lines="8" android:maxLines="3" android:minLines="6" android:scrollbairs="viewtical" /> </LineairLayout> <EditText <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center_horizontal" android:orientation="viewtical"> <EditText android:id="@+id/etComments" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:gravity="top" android:hint="Enter comments(Optional)" android:inputType="textMultiLine" android:lines="8" android:maxLines="3" android:minLines="6" android:scrollbairs="viewtical" /> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center_horizontal" android:orientation="viewtical"> <EditText android:id="@+id/etComments" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:gravity="top" android:hint="Enter comments(Optional)" android:inputType="textMultiLine" android:lines="8" android:maxLines="3" android:minLines="6" android:scrollbairs="viewtical" /> </LineairLayout> 

     final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null); AlertDialog alertDialog = new AlertDialog.Builder(ct).create(); alertDialog.setTitle("Your Title Here"); alertDialog.setIcon("Icon id here"); alertDialog.setCancelable(false); Constant.alertDialog.setMessage("Your Message Here"); final EditText etComments = (EditText) view.findViewById(R.id.etComments); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss() } }); alertDialog.setView(view); alertDialog.show(); } final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null); AlertDialog alertDialog = new AlertDialog.Builder(ct).create(); alertDialog.setTitle("Your Title Here"); alertDialog.setIcon("Icon id here"); alertDialog.setCancelable(false); Constant.alertDialog.setMessage("Your Message Here"); final EditText etComments = (EditText) view.findViewById(R.id.etComments); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss() } }); alertDialog.setView(view); alertDialog.show(); }); final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null); AlertDialog alertDialog = new AlertDialog.Builder(ct).create(); alertDialog.setTitle("Your Title Here"); alertDialog.setIcon("Icon id here"); alertDialog.setCancelable(false); Constant.alertDialog.setMessage("Your Message Here"); final EditText etComments = (EditText) view.findViewById(R.id.etComments); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss() } }); alertDialog.setView(view); alertDialog.show(); } final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null); AlertDialog alertDialog = new AlertDialog.Builder(ct).create(); alertDialog.setTitle("Your Title Here"); alertDialog.setIcon("Icon id here"); alertDialog.setCancelable(false); Constant.alertDialog.setMessage("Your Message Here"); final EditText etComments = (EditText) view.findViewById(R.id.etComments); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss() } }); alertDialog.setView(view); alertDialog.show(); }); final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null); AlertDialog alertDialog = new AlertDialog.Builder(ct).create(); alertDialog.setTitle("Your Title Here"); alertDialog.setIcon("Icon id here"); alertDialog.setCancelable(false); Constant.alertDialog.setMessage("Your Message Here"); final EditText etComments = (EditText) view.findViewById(R.id.etComments); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss() } }); alertDialog.setView(view); alertDialog.show(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.