sapamlucy
sapamlucy

Reputation: 306

how to get the id of the current image shown on viewPager

@Override
        public void onClick(View v) {
            try {
                //Write fileObject tag = imageView.getTag();                  

                //Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.c);

            Bitmap bmp= BitmapFactory.decodeResource(getResources(),v.getResources().getResourceName((Integer)v.getTag()));


                String filename = "bitmap.png";
                FileOutputStream stream = getApplicationContext().openFileOutput(filename, Context.MODE_PRIVATE);
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

                //Cleanup
                stream.close();
                bmp.recycle();

i want to add the image id from viewPager instead of the R.drawable.img1, any1 please any help? i have edited my question, instaed of getting image from drawable i need to get ithe current image on viewPager. how do i do it?

Upvotes: 1

Views: 1856

Answers (2)

sapamlucy
sapamlucy

Reputation: 306

i have found the solution to this

Bitmap bmp=getBitmapFromView(viewPager.getChildAt(1));

i got my solution with this, thanks for all your feedbacks

Upvotes: 1

Aparupa Ghoshal
Aparupa Ghoshal

Reputation: 309

View Pager must be having an adapter. In getView method, set position as tag to the imageviews. Then for each positions , access the imageviews as per requirement.

Upvotes: 0

Related Questions