1

我为我的列表视图创建了一个自定义 adpater,并创建了我的自定义对话框,其中包含一个列表视图,但我不知道如何将数据链接到自定义对话框中的列表视图(我在解释这一点方面做得非常糟糕知道)。我的适配器使用具有复选框的列表视图,我想知道在下次打开应用程序时是否检查了我如何存储。我将把它分成几个步骤,这样它就不会那么混乱:我想:在我现有的自定义对话框中使用我的适配器创建一个列表视图,为下次打开应用程序时存储复选框的状态。

(它没有显示,但我的列表视图称为 listviewdialog)

我的主要活动(只是自定义对话框位)

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

我的自定义适配器:

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

1 回答 1

1

在设置对话框的部分:

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);
于 2012-04-22T17:55:03.620 回答