Android – Using Listview In a custom dialog (android)

androidcustomdialoglistview

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(R.id.button01);

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

      public void onClick(View arg0) {

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


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


        Button dialogButton = (Button) dialog.findViewById(R.id.Button01);
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
      }
    });

My Custom Adapter:

package kevin.erica.box;

import kevin.erica.box.R;

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;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.list_adapter, parent, false);
    CheckBox textView = (CheckBox) rowView.findViewById(R.id.checkBox1);
    textView.setText(values[position]);



    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(R.id.listviewdialog);
mListView.setAdapter(mAdapter);