Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在自定义对话框中使用Listview(android)_Android_Listview_Customdialog - Fatal编程技术网

在自定义对话框中使用Listview(android)

在自定义对话框中使用Listview(android),android,listview,customdialog,Android,Listview,Customdialog,我已经为我的列表视图创建了一个自定义Adpeter,也创建了一个带有列表视图的自定义对话框,但是我不知道如何在自定义对话框中将数据链接到列表视图中(我知道我在解释这个方面做得很差)。我的适配器使用带有复选框的listview,我想知道下次打开应用程序时,如果有复选框或没有复选框,我如何存储。 我将把它分为几个步骤,这样就不会那么混乱了: 我想: 在现有自定义对话框中使用我的适配器创建列表视图, 存储复选框的状态,以便下次打开应用程序时使用 (未显示,但我的listview称为listviewdi

我已经为我的列表视图创建了一个自定义Adpeter,也创建了一个带有列表视图的自定义对话框,但是我不知道如何在自定义对话框中将数据链接到列表视图中(我知道我在解释这个方面做得很差)。我的适配器使用带有复选框的listview,我想知道下次打开应用程序时,如果有复选框或没有复选框,我如何存储。 我将把它分为几个步骤,这样就不会那么混乱了: 我想: 在现有自定义对话框中使用我的适配器创建列表视图, 存储复选框的状态,以便下次打开应用程序时使用

(未显示,但我的listview称为listviewdialog)

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

我的自定义适配器:

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;
}
 }
package kevin.erica.box;
导入kevin.erica.box.R;
导入android.content.Context;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.CheckBox;
导入android.widget.ImageView;
导入android.widget.TextView;
公共类MobileArrayAdapter扩展了ArrayAdapter{
私人最终语境;
私有最终字符串[]值;
公共MobileArrayAdapter(上下文,字符串[]值){
super(上下文、R.layout.list\u适配器、值);
this.context=上下文;
这个值=值;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutFlater充气器=(LayoutFlater)上下文
.getSystemService(上下文布局\充气机\服务);
视图行视图=充气机。充气(R.layout.list\u适配器,父级,false);
复选框textView=(复选框)rowView.findViewById(R.id.checkBox1);
setText(值[位置]);
返回行视图;
}
}

在设置对话框的部分:

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

在设置对话框的部分:

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

那么,我该如何将我的数据放入其中呢?:)最后一件事,它说MobileArrayAdapter不能解析为mListView.setAdapter(MobileArrayAdapter)中的变量@用户1337110请参见上面的编辑。不过,对于持久性,您最好创建一个数据库,并使用CursorAdapter对其进行调整,而不是使用arrayadapter。我有两个错误。我得到一个构造函数MobileArrayAdapter(new View.OnClickListener(){},String[])是未定义的错误,myAdapter无法解析为变量错误,无论如何都要修复它?@user1337110应该仔细阅读您的代码-上面编辑过,然后如何将我的数据放入其中?:)最后一件事,它说MobileArrayAdapter不能解析为mListView.setAdapter(MobileArrayAdapter)中的变量@用户1337110请参见上面的编辑。不过,对于持久性,您最好创建一个数据库,并使用CursorAdapter对其进行调整,而不是使用arrayadapter。我有两个错误。我发现构造函数MobileArrayAdapter(new View.OnClickListener(){},String[])是未定义的错误,myAdapter无法解析为变量错误,无论如何都要修复它吗?@user1337110应该仔细阅读您的代码-在上面进行了编辑