Problema de espaciado de diálogo de alerta con texto y editar texto

No puedo ver "MIS DATOS" en mi AlertDialog, ya que se superpone con el EditText.

Context context = MyActivity.this; AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle(" NEW TITLE"); alert.setMessage("MESSAGE 1"); final TextView tx = new TextView(this); tx.setText("MY DATA"); alert.setView(tx); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input); alert.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked OK so do some stuff */ } }); alert.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked Cancel so do some stuff */ } }); alert.create(); alert.show(); 

Prueba esto:

 LinearLayout layout = new LinearLayout(this); layout.setOrientation(Vertical); final TextView tx = new TextView(this); tx.setText("MY DATA"); layout.addView(tx); // Set an EditText view to get user input final EditText input = new EditText(this); layout.addView(input); alert.setView(layout); 

Sólo puede establecer una vista con setView por lo que no es que "MIS DATOS" no esté visible – es que no existe en absoluto ya que está siendo sobrescrita por su EditText. Cambia el orden en el que llamas setView para ver lo que quiero decir.

Para tener varias vistas como la vista personalizada necesitará crear un ViewGroup como LinearLeayout, añada EditText y TextView a este grupo y, a continuación, establezca el grupo como su vista de diálogo personalizada.

 // Create a ViewGroup to hold the other views LinearLayout group = new LinearLayout(this); group.setOrientation(LinearLayout.VERTICAL); // Header for the TextView final TextView txHeader = new TextView(this); txHeader.setText("TEXTVIEW HEADER"); group.addView(txHeader); // Add the textview to the group final TextView tx = new TextView(this); tx.setText("MY DATA"); group.addView(tx); // Header for the EditText final TextView inputHeader = new TextView(this); inputHeader.setText("EDIT-TEXT HEADER"); group.addView(inputHeader); final EditText input = new EditText(this); group.addView(input); // Set the group as the custom dialog view alert.setView(group); 

Sugiero utilizar un cuadro de diálogo personalizado, definir un diseño xml, por ejemplo:

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/plausi" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@color/tree_normal_back" android:padding="3dip"> <TextView android:id="@+id/plausi_tv" android:layout_width="fill_parent" android:textSize="22dip" android:padding="2dip" android:layout_height="wrap_content" android:background="@color/tree_normal_back" android:textColor="@color/tree_normal_font" android:minLines="4"/> <EditText android:layout_below="@+id/plausi_tv" android:id="@+id/plausi_et" android:layout_width="fill_parent" android:textSize="22dip" android:padding="2dip" android:layout_height="wrap_content" android:textColor="@color/tree_input_font"/> </RelativeLayout> 

y construir el diálogo como:

 LayoutInflater mInflater = LayoutInflater.from(tab3.this); AlertDialog.Builder builder = new AlertDialog.Builder(tab3.this); builder.setTitle("Plausibilitätscheck"); View convertView = mInflater.inflate(R.xml.plausi, null); RelativeLayout rl = (RelativeLayout) convertView.findViewById(R.id.plausi); final EditText et = (EditText) convertView.findViewById(R.id.plausi_et); final TextView tv = (TextView) convertView.findViewById(R.id.plausi_tv); tv.setText(Html.fromHtml(vorgabe)); et.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); et.setText(GlobalVars.form_adapter.DATA[clicked_index]); et.addTextChangedListener(new TextWatcher(){ @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } }); builder.setPositiveButton("OK", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } } }); builder.setView(rl); final AlertDialog alert = builder.create(); et.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); alert.show(); 

prueba este código

"LayoutInflater factory = LayoutInflater.from (nextScreen.this); final Ver textEntryView = factory.inflate (R.layout.text_entry, null);
final AlertDialog.Builder meeting = nuevo AlertDialog.Builder (nextScreen.this); meeting.setView (textEntryView) .setTitle ("Ok"); meeting.setPositiveButton ("Create", nuevo DialogInterface.OnClickListener () {

  @Override public void onClick(DialogInterface dialog, int which) { TextView txt=(TextView) textEntryView.findViewById(R.id.username_edit); Toast.makeText(nextScreen.this, txt.getText().toString(), Toast.LENGTH_SHORT); } }); meeting.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); meeting.create(); meeting.show();" 

y también en el archivo .xml

 <EditText android:id="@+id/username_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:scrollHorizontally="true" android:autoText="false" android:capitalize="none" android:gravity="fill_horizontal" android:singleLine="true"/> 

  • Creación de la caja de conmutación onClickListener para TextView
  • Actualización de Android TextView en subprocesos y ejecución
  • Diseño de mensajes de WhatsApp - Cómo obtener una vista de tiempo en la misma fila
  • Android - Centro de vista de texto en LinearLayout
  • android: límite de 10 caracteres por línea TextView
  • La carátula de TextView de Android no funciona
  • Convertir el número en textview en int
  • TextView`s LinkMovementMethod bloquea el evento de toque listitem
  • Desplazamiento de TextView en una ScrollView a una subcadena de texto específica
  • La gravedad de TextView no funciona con hebreo
  • Problema al usar una fuente personalizada - "no se puede hacer el tipo de letra nativo"
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.