Gridview - Click image to view image in Viewpager

前端 未结 4 1132
慢半拍i
慢半拍i 2021-01-01 00:23

This is a gridview that get image from json. and it works fine. I want to click image in this gridview to show full image and can slide it. I find the solution of this probl

相关标签:
4条回答
  • 2021-01-01 00:50

    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);
    
                }
            });
    
    0 讨论(0)
  • 2021-01-01 00:58

    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

    0 讨论(0)
  • 2021-01-01 01:01

    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

    0 讨论(0)
  • 2021-01-01 01:09

    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.

    0 讨论(0)
提交回复
热议问题