Android – Using Listview In a custom dialog (android)


Ive created a custom adpater for my list view aswell as having created my custom dialog with a list view in it but i have no idea how to link the data into the listview in the custom dialog (im doing a really bad job of explaining this i know). My adapter uses a listview that has checkbox's and i would like to know how im able to store if there checked or not for the next time the application is open.
I'll put it into steps so its not so confusing:
I want to:
Create a list view with my adapter inside my existing custom dialog,
Store the state of the checkbox's for the next time the application is open.

(its not shown but my listview is called listviewdialog)

My main activity (just the custom dialog bit)

button = (Button) findViewById(;

    // add button listener
    button.setOnClickListener(new OnClickListener() {

      public void onClick(View arg0) {

        // custom dialog
        final Dialog dialog = new Dialog(context);
        dialog.setTitle("The List");

        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(;
        text.setText("Did you not read the button? :P i'm not finshed on this yet XD");

        Button dialogButton = (Button) dialog.findViewById(;
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

My Custom Adapter:



import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;

public MobileArrayAdapter(Context context, String[] values) {
    super(context, R.layout.list_adapter, values);
    this.context = context;
    this.values = values;

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
    View rowView = inflater.inflate(R.layout.list_adapter, parent, false);
    CheckBox textView = (CheckBox) rowView.findViewById(;

    return rowView;

Best Solution

In the part where you set up your dialog:

String[] mData;
// get your data; I don't know where its coming from
MobileArrayAdapter mAdapter = new MobileArrayAdapter(getContext(), mData);
ListView mListView = (ListView) dialog.findViewById(;