【问题标题】:How to set gridview within listview item and click on each grid item with uniq posion and click evant如何在列表视图项中设置网格视图并单击具有 uniq 位置的每个网格项并单击 evant
【发布时间】:2015-12-08 11:22:12
【问题描述】:

我想用图像网格日期明智地关注列表视图。首先获取图像的日期列表,然后在获取特定日期图像列表的图像路径列表之后。最后我填充特定日期图像的列表和网格(没有图片和日期不固定),看看屏幕截图。 Date wise images display in Grid View

现在我的问题是,当我在图像上设置单击侦听器并在单击时添加复选标记图像然后图像添加到两个位置时,为什么我不知道。第二个是当我向下滚动列表视图时复选标记可见走了。

我想选择多张图片并添加复选标记图片并执行“删除图片”和“分享图片”等操作

Like this

我调用每个列表项的网格适配器,看看我的代码告诉我出了什么问题

自定义列表视图适配器:获取视图方法

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    View row = convertView;

    ViewHolder viewHolder = new ViewHolder();

    DateSortedImageItem item = getItem(position);

    if (row == null) {

        row = mInflator.inflate(R.layout.row_date_sorted_image_list, parent, false);
        viewHolder.tv_date = (TextView) row.findViewById(R.id.tv_row_date);
        viewHolder.rowGridView = (GridView) row.findViewById(R.id.gv_row_item);

        viewHolder.tv_date.setText(item.getDate());

        row.setTag(viewHolder);

        gridAdapter = new GridAdapter(context, R.layout.row_sorted_image_gridview_item,
                item.getDateSortedImageList(), position);

        viewHolder.rowGridView.setAdapter(gridAdapter);

    } else {
        row.getTag();
    }

    return row;
}

private class ViewHolder {
    TextView tv_date;
    GridView rowGridView;
}

我的网格适配器代码是:

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

    if (convertView == null) {
        LayoutInflater mInflater = ((Activity) getContext()).getLayoutInflater();
        convertView = mInflater.inflate(R.layout.row_sorted_image_gridview_item, parent, false);

    }
    view = convertView;
    final SquareImageView imageView = (SquareImageView) view.findViewById(R.id.iv_test_row_grid_img);

    final ImageView iv_checked = (ImageView) view.findViewById(R.id.iv_checked);
    final ImageView iv_unChecked = (ImageView) view.findViewById(R.id.iv_unchecked);

    view.setTag(arrList.get(position).toString());

    File f = new File(arrList.get(position).toString());
    System.out.println("arrList size >>" + arrList.size());
    Picasso.with(context).load(Uri.fromFile(f)).resize(100, 100).centerCrop().placeholder(R.drawable.ic_launcher)
            .error(R.drawable.ic_close_black).into(imageView);

我刚刚设置了网格视图图像。现在我设置 imageview click ivent 并添加复选标记然后添加复选标记事件两个地方并向下滚动然后可见也消失了。

听到什么错误以及如何将图像视图的点击事件设置为唯一。 最后我想设计看起来像谷歌“照片”的应用程序。 建议我任何示例或库:

【问题讨论】:

    标签: android android-layout listview gridview


    【解决方案1】:

    首先你应该创建一个POJO,如下所示

    public class AlbumItem {
        private String headerStr;
        private List<ChildItem> children;
    
        //getter - setter....
        public class ChildItem {
            private String childName;
            private boolean isSelected;
    
            //getter - setter.....
        }
    }
    

    现在在你的主适配器中使用这个POJO

    在第二个适配器句柄中,选择逻辑意味着如果isSelected 为真,则显示iv_checked,否则显示iv_unchecked

    如果您需要进一步解释,请告诉我。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-17
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      相关资源
      最近更新 更多