0

在我的 android 应用程序中,我使用分页来使用列表视图显示我的所有产品。在listview 里面有一个checkBox 和一个imageview。我正在使用复选框从列表视图中选择特定图像。我正在从服务器获取所有图像。首先,我在 ArryList 中获取所有图像,然后在 android 临时 ArrayList 中获取 5 个元素,并将该临时元素用于自定义数组适配器并加载该 5 个图像。问题是当我选择一个复选框来选择特定图像并单击下一步按钮然后在新页面内我得到另一个选中的复选框。除此之外,我在每一页中都有一个选定的按钮。如何删除这个?我想要在我点击过的 Checked 中的那个复选框。我的代码如下。

private class MyCustomAdapter extends ArrayAdapter<WatchListAllEntity> {

    private static final int TYPE_ITEM = 0;
    private static final int TYPE_ITEM_WITH_HEADER = 1;
    private ArrayList<WatchListAllEntity> mData = new ArrayList();
    private LayoutInflater mInflater;
    private ArrayList<WatchListAllEntity> items = new ArrayList<WatchListAllEntity>();

    public MyCustomAdapter(Context context, int textViewResourceId,
            ArrayList<WatchListAllEntity> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    public void addItem(WatchListAllEntity watchListAllEntity) {

        items.add(watchListAllEntity);
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;
        final int position1 = position;
        if (v == null) {

            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.listitempict, null);
        }
        watchListAllEntity = new WatchListAllEntity();
        watchListAllEntity = items.get(position);
        Log.i("position: iteamsLength ", position + ", " + items.size());
        if (watchListAllEntity != null) {

            ImageView itemImage = (ImageView) v
                    .findViewById(R.id.imageviewproduct);

            if (watchListAllEntity.get_thumbnail_image_url1() != null) {

                Drawable image = Utility.ImageOperations(watchListAllEntity.get_thumbnail_image_url1().replace(" ", "%20"),"image.jpg");



                if (image != null) {
                    itemImage.setImageDrawable(image);
                    itemImage.setAdjustViewBounds(true);
                } else {

                    itemImage.setImageResource(R.drawable.iconnamecard);
                }

                Log.i("status_ja , status",
                        watchListAllEntity.get_status_ja() + " ,"
                                + watchListAllEntity.getStatus());

                int NewtheStatus = Integer.parseInt(watchListAllEntity
                        .getStatus());
                CheckBox checkBox = (CheckBox) v
                        .findViewById(R.id.checkboxproduct);
                TextView alreadyOrderText = (TextView) v
                        .findViewById(R.id.alreadyordertext);
                if (NewtheStatus == 1) {
                    alreadyOrderText.setVisibility(4);

                    checkBox.setVisibility(0);
                } else {
                    checkBox.setVisibility(4);
                    alreadyOrderText.setVisibility(0);
                }
                Log.i("Loading ProccardId: ",
                        watchListAllEntity.get_proc_card_id() + "");
                checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                        WatchListAllEntity watchListAllEntity2 = items
                                .get(position1);
                        Log.i("Position: ", position1 + "");

                        if (isChecked) {

                            Constants.orderList.add(watchListAllEntity2
                                    .get_proc_card_id());
                            Log.i("Proc Card Id Add: ",
                                    watchListAllEntity2.get_proc_card_id()
                                            + "");


                        } else {
                            Constants.orderList.remove(watchListAllEntity2
                                    .get_proc_card_id());
                            Log.i("Proc Card Id Remove: ",
                                    watchListAllEntity2.get_proc_card_id()
                                            + "");

                        }

                    }
                });
            }

        }

        return v;
    }
4

1 回答 1

0

检查 newpage.xml 文件中的 CheckBox 元素是否包含 android:checked="true" 语句。

于 2012-08-08T08:44:21.517 回答