I have an AlertDialog in which I set the layout (inside TextView and EditText) through the setView () method and placed the listView through the setMultiChoiceItems method, but when I run the dialog, the listView is displayed first and then the layout. and then ListView

LayoutInflater factoryClient = LayoutInflater.from(this); final View view=factoryClient.inflate(R.layout.dialog_layout,null); question=(TextView)view.findViewById(R.id.tv_question); ask=(EditText)view.findViewById(R.id.edit_ask); question.setText(alarm_name); String[] plans_name=getPlansName(plans_list); final boolean[] mCheckPlan=getPlanDone(plans_list); AlertDialog.Builder alert_dialog=new AlertDialog.Builder(this) .setTitle(alarm_time) .setIcon(R.mipmap.ic_dialog_time) .setView(view) .setMultiChoiceItems(plans_name, mCheckPlan, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { mCheckPlan[which] = isChecked; } }) .setCancelable(false); //закрытие диалога через кнопку назад alert_dialog.setPositiveButton("Да", null); alert_dialog.setNegativeButton("Нет", null); alert_dialog.setNeutralButton("Отложить", null); final AlertDialog alertDialog=alert_dialog.create(); alertDialog.show(); 
  • This is Java code - Vladimir

1 answer 1

Judging by en-SO , the problem can be solved by setting your markup as the dialog title (and not its contents ( setView method)) using the setCustomTitle method setCustomTitle this:

 AlertDialog.Builder alert_dialog=new AlertDialog.Builder(this) .setTitle(alarm_time) .setIcon(R.mipmap.ic_dialog_time) .setCustomTitle(view, null) .setMultiChoiceItems(plans_name, mCheckPlan, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { mCheckPlan[which] = isChecked; } }) .setCancelable(false); //закрытие диалога через кнопку назад 

In order for this text input field to react to a click and launch the keyboard, you must set the corresponding flags as follows :

 AlertDialog alert_dialog = builder.show(); d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
  • Thanks for the advice, it came out, but I'm losing the Title (setTitle ()), is it possible to somehow leave both that and that? - Vladimir
  • one
    dialog_layout , just add the text field at the top to the dialog_layout markup and display the title there) - Yuriy SPb
  • I didn’t realize it. Thank you, it came out)) - Vladimir
  • one
    @Vladimir, if my answer solved your problem, then you can vote for it and mark it "true" - YuriySPb
  • one
    @ Vladimir, try this solution - YuriySPb