Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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
Android 获取从CustomListView检查的项的名称,并在下一个意图中传递该项_Android_Android Listview - Fatal编程技术网

Android 获取从CustomListView检查的项的名称,并在下一个意图中传递该项

Android 获取从CustomListView检查的项的名称,并在下一个意图中传递该项,android,android-listview,Android,Android Listview,我已经创建了一个应用程序在我的应用程序中我创建了自定义列表视图,在列表视图中我添加了一个复选框,图像视图和2文本视图现在我想在选中的下一个活动中传递数据。 我该怎么做? ChannelListView.java public class ChannelListView extends Activity implements OnItemClickListener { CheckBox checkMarks; ListView allChannels; ArrayAdapt


我已经创建了一个应用程序
在我的应用程序中我创建了自定义
列表视图
,在列表视图中我添加了一个
复选框
图像视图
和2
文本视图

现在我想在选中的下一个活动中传递数据。
我该怎么做?
ChannelListView.java

public class ChannelListView extends Activity implements OnItemClickListener {
    CheckBox checkMarks;
    ListView allChannels;
    ArrayAdapter<DisplayChannelListData> adapter;
    Button send, back;
    DatabaseHelper dbHelper;
    List<DisplayChannelListData> channelListData;
    ChannelListView channelListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);
        channelListView = this;
        dbHelper = new DatabaseHelper(getApplicationContext());
        allChannels = (ListView) findViewById(R.id.listviewAllChannel);
        send = (Button) findViewById(R.id.btnListSend);
        back = (Button) findViewById(R.id.btnListBack);

        adapter = new ListViewAdapter(this, getListViewModel());
        allChannels.setAdapter(adapter);
        allChannels.setOnItemClickListener(this);

        send.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChannelListView.this, ChannelList.class);
                startActivity(intent);

            }
        });
    }

    private List<DisplayChannelListData> getListViewModel() {
        channelListData = dbHelper.displayChannelsList(channelListView);

        return channelListData;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        checkMarks = (CheckBox) view.findViewById(R.id.chkAllCheckMark);
        if (!checkMarks.isChecked()) {
            checkMarks.setChecked(true);

        } else {
            checkMarks.setChecked(false);
        }

    }

}

检查时维护one ArrayList,如:

ArrayList<DisplayChannelListData> checkedChannelList=new ArrayList<DisplayChannelListData>();

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    checkMarks = (CheckBox) view.findViewById(R.id.chkAllCheckMark);
    if (!checkMarks.isChecked()) {
        checkMarks.setChecked(true);
        checkedChannelList.add(channelListData.get(position));

    } else {
        checkMarks.setChecked(false);
        checkedChannelList.remove(channelListData.get(position));
    }

}

错误putParcelableArrayListExtra:方法putParcelableArrayListExtra(String,ArrayListYou可以在DisplayChannelListDataOk中实现Parcelable。我如何在下一个活动中获取此数据?使用getIntent().getExtras().getString(“CHANNELSLIST”);这是正确的方法吗?使用此getIntent().getExtras().getParcelableArrayList(“CHANNELSLIST”);我将在此getIntent行中得到一个异常…java.lang.RuntimeException:无法启动活动组件信息{com.example.Demo/com.example.Demo.ChannelList}:android.os.BadParcelableException:Parcelable协议要求在com.example.Demo.DisplayChannelListData类上有一个名为Creator的Parcelable.Creator对象
public class DisplayChannelListData {
    private boolean selected;
    private int drawable_path;
    private String channel_name;
    private String channel_desc;

    public DisplayChannelListData(int path,String name,String desc){
        this.drawable_path = path;
        this.channel_name = name;
        this.channel_desc = desc;
    }

    public int getDrawable_path() {
        return drawable_path;
    }

    public void setDrawable_path(int drawable_path) {
        this.drawable_path = drawable_path;
    }

    public String getChannel_name() {
        return channel_name;
    }

    public void setChannel_name(String channel_name) {
        this.channel_name = channel_name;
    }

    public String getChannel_desc() {
        return channel_desc;
    }

    public void setChannel_desc(String channel_desc) {
        this.channel_desc = channel_desc;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }




}
ArrayList<DisplayChannelListData> checkedChannelList=new ArrayList<DisplayChannelListData>();

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    checkMarks = (CheckBox) view.findViewById(R.id.chkAllCheckMark);
    if (!checkMarks.isChecked()) {
        checkMarks.setChecked(true);
        checkedChannelList.add(channelListData.get(position));

    } else {
        checkMarks.setChecked(false);
        checkedChannelList.remove(channelListData.get(position));
    }

}
send.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(ChannelListView.this, ChannelList.class);
            intent.putParcelableArrayListExtra("CHANNELSLIST", checkedChannelList);
            startActivity(intent);

        }
    });