如何在gridview的每个单元格中的imageview的右下角设置复选框

时间:2018-06-06 13:13:06

标签: android gridview

当用户使用复选框从Gridview中选择图像数量并单击“提交”按钮,然后添加所有选定的项目并在另一个活动中显示这些项目。

    public class AndroidGridLayoutActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid_layout);

        GridView gridView = (GridView) findViewById(R.id.grid_view);

        // Instance of ImageAdapter Class
        gridView.setAdapter(new ImageAdapter(this));
 gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {

                // Sending image id to FullScreenActivity
                Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
                // passing array index
                i.putExtra("id", position);
                startActivity(i);
            }
        });
    }
}

1 个答案:

答案 0 :(得分:0)

覆盖您的ImageAdapter getView()方法。

为GridView项目创建单独的布局。将ImageView和CheckBox放在此布局中。下面的小代码片段。它没有满,你可以完成它;)

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.grid_view_item, parent, false);
    }

    return convertView;
}