Gridview - Click image to view image in Viewpager

女生的网名这么多〃 提交于 2019-11-30 09:40:58

its same as you need. just click event of grid view and get image in next screen using view pager.

Click event of grid view images:

GridView gridView = (GridView) findViewById(R.id.gridview);
        gridView.setAdapter(new ImageAdapter());
        gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) 
         {
          HashMap<String, Object> selected = (HashMap<String, Object>)  

          gridView.getItemAtPosition(position);

            }
        });

First of all you have to implement ImageAdapter class' method getItem(int position) to return the item at "position" in MyArr. Next, in click listener, you can do something like

HashMap<String, Object> selected = (HashMap<String, Object>) gridView.getItemAtPosition(position);

With selected you have your bitmap.

See this class you can find

GridView gridView = (GridView) findViewById(R.id.gridview);
        gridView.setAdapter(new ImageAdapter());
        gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                startImageGalleryActivity(position);
            }
        });

Here you will get same output what you wants.

You can also download complete source code here

Sansan Fardiyansyah

is this url of your image?

-> map.put("photo", (String) c.getString("photo"));//on your main activity

try using onclick on myView

myView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        result = MyArr.get(position);
        Intent intent = new Intent(context, youractivitytarget.class);
        intent.putExtra("photo", (String)result.get(MainActivity.PHOTO));
        context.startActivity(intent);
    }
});

then use url to download your clicked photo again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!