How to set item as selected in alert dialog?
<p>I am showing an alert dialog to choose the list. Now I want to show the default list as selected in the alert dialog. I have attached the custom adapter to the list. I have used setSingleChoiceItems in the dialog.</p>

<p>For this I have set the second argument to 0 but still I am unable to see the selected item.</p>

<p>code:</p>

<pre><code>   ArrayList&lt;ListData&gt; allTables = new ArrayList&lt;&gt;();

        allTables = mListTableHelper.getAllList();

        final ListData taskList = new ListData();
        taskList.setId(100000000);
        taskList.setTitle("Default List");
        allTables.add(0, taskList);

        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(AddTaskActivity.this);
        LayoutInflater inflater = getLayoutInflater();
        View convertView = (View) inflater.inflate(R.layout.tablelist, null, false);

        ListView lv = (ListView) convertView.findViewById(R.id.tableslist);

        final ListItemAdapter adapter = new ListItemAdapter(AddTaskActivity.this,allTables);


        alertDialog.setSingleChoiceItems(adapter, 0 , new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,int which) {


                ListData listOject = new ListData();

                listOject = listData.get(which);

                mListId = listOject.getId();

                //   listOject = mListTableHelper.getList(mListId);

                String title = listOject.getTitle();

                list.setText(listOject.getTitle());

                dialog.dismiss();

            }

        }).create();

        alertDialog.show();
</code></pre>

<p>ListItemAdapter</p>

<p>I tried as suggested, still dint get the selected item.</p>

<p>public class ListItemAdapter extends ArrayAdapter{</p>

<pre><code>int selectedItem;


    private static class ViewHolder {
        TextView title;
        RadioButton rb;
    }

    public ListItemAdapter(Context context, ArrayList&lt;ListData&gt; users,int selectedItem) {
        super(context, R.layout.list_item, users);
        this.selectedItem = selectedItem;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        ListData item = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        ViewHolder viewHolder; // view lookup cache stored in tag
        if (convertView == null) {
            viewHolder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(R.layout.list_item, parent, false);
            viewHolder.title = (TextView) convertView.findViewById(R.id.list_item);
            viewHolder.rb = (RadioButton) convertView.findViewById(R.id.radioButton);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        // Populate the data into the template view using the data object
        viewHolder.title.setText(item.getTitle());

        // Return the completed view to render on screen
        return convertView;
    }
</code></pre>

<p>}</p>

<p>adapter initialization</p>

<pre><code>   final ListItemAdapter adapter = new ListItemAdapter(AddTaskActivity.this,allTables,0);
</code></pre>

<p>EDIT:</p>

<p>Removed .Create() method. It shows an error over alert dialog initialization.</p>

<pre><code>    public void showCustomList() {

        mAllLists = new ArrayList&lt;&gt;();

        mAllLists = mListTableHelper.getAllList();

        final ListData taskList = new ListData();
        taskList.setId(100000000);
        taskList.setTitle("Default List");
        mAllLists.add(0, taskList);


        alertDialog = new AlertDialog(AddTaskActivity.this);


        LayoutInflater inflater = getLayoutInflater();
        View convertView = (View) inflater.inflate(R.layout.tablelist, null, false);

        ListView lv = (ListView) convertView.findViewById(R.id.tableslist);

        final ListItemAdapter adapter = new ListItemAdapter(AddTaskActivity.this,mAllLists,selectedItem);


       alertDialog.setAdapter(adapter,null);

        alertDialog.show();

    }
</code></pre>

<p>What's wrong here? Thank you..</p>