Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display single choice AlertDialog with custom views?
    primarykey
    data
    text
    <p>I need to make custom AlertDialog with single choice, but without radio buttons and with two custom TextViews in each item. I've try to use AlertDialog:</p> <pre><code>ArrayList&lt;HashMap&lt;String,String&gt;&gt; items=new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); //..here I fill my ArrayList SimpleAdapter simpleAdapter=new SimpleAdapter(this, items, R.layout.list_item, new String[] {"name","count"}, new int[] {R.id.name,R.id.count}); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setSingleChoiceItems(simpleAdapter, -1, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //Here I handle click }}); alert.show(); </code></pre> <p>But it doesn't close after click on item. Why? May be I can fix it?</p> <p>Alternatively, I've try to use Dialog for it:</p> <pre><code>ArrayList&lt;HashMap&lt;String,String&gt;&gt; items=new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); //..here I fill my ArrayList SimpleAdapter simpleAdapter=new SimpleAdapter(this, items, R.layout.list_item, new String[] {"name","count"}, new int[] {R.id.name,R.id.count}); Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); View view=LayoutInflater.from(this).inflate(R.layout.items_list, null); ListView listView=(ListView) view.findViewById(R.id.list_view); listView.setAdapter(simpleAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { //Here I handle click dialog.dismiss(); }}); dialog.setContentView(view); dialog.show(); </code></pre> <p>But it have problem with styles and text doesn't showing (text color coincide with background color).</p> <p>I think that AlertDialog preferably for me. But how to make it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload