0

I have written the code in which I am getting the result from database which I am binding to listview successfully.But Now I want that listview in Custom dialog format.Means List data should come in dialog.How to attach the listdata to custom dialog box ?

final Cursor cursor = dbHelper.fetchAllRecords();
        String[] columns = new String[] {
                RecordsDbAdapter.KEY_NAME,
                RecordsDbAdapter.KEY_BIRTHDAY,

        };
        int[] to = new int[] {
                R.id.name,
                R.id.birthdate,
        };
        dataAdapter = new SimpleCursorAdapter(
                this, R.layout.row,
                cursor,
                columns,
                to);
        ListView listView = (ListView) findViewById(R.id.list);
        listView.setAdapter(dataAdapter);
user1758835
  • 215
  • 4
  • 17
  • http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList – Niranj Patel Oct 30 '12 at 06:24
  • I have seen that But I am not able to understand how to add my listview data to custom Dialogbox.Means I am getting data in ListView listView = (ListView) findViewById(R.id.list);how to attach it – user1758835 Oct 30 '12 at 06:26
  • possible duplicate of [Dialog with list view and message](http://stackoverflow.com/questions/6423706/dialog-with-list-view-and-message) – Niranj Patel Oct 30 '12 at 06:27

1 Answers1

0

You can bind an adapter to an AlertDialog:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setAdapter(dataAdapter, new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {

        // Stuff that happens when an item is clicked
    }
});
builder.show();
Jason Robinson
  • 31,005
  • 19
  • 77
  • 131