Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to set images from horizontal scrollview into the viewpager in android?  RSS feed

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written a program in which i am displaying a gridview of images and when i click on the image another activity opens which has a viewpager to slide my images and there is also a horizontal scrollview at the bottom of the same page which has the same images which is seen in my gridview , till here everything works fine , and yea all the images are being read from my sdcard Now when i click on the images inside my horizontal scrollview , the image which is displayed up in my viewpager should change , example , like the gallery of s4 , so i am not getting how to do it

My Code :Inside my imageview.onclick i do not know what to do for my program to work , please provide suggestions according to my program ,please need some help

public class FullScreenViewActivity extends Activity {

private Utils utils;
private FullScreenImageAdapter adapter;
private ViewPager viewPager;
LinearLayout myGallery;
ImageView iView;
int i;
String path;
int id;
File[] files;
HorizontalScrollView scrollView;
int position;

protected void onCreate(Bundle savedInstanceState) {

viewPager = (ViewPager) findViewById(;
myGallery = (LinearLayout) findViewById(;
scrollView = (HorizontalScrollView) findViewById(;
String ExternalStorageDirectoryPath = Environment

String targetPath = ExternalStorageDirectoryPath + "/Pictures/raw";
Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG)
File targetDirector = new File(targetPath);

files = targetDirector.listFiles();

for (File file : files) {



utils = new Utils(getApplicationContext());

Intent i = getIntent();
position = i.getIntExtra("position", 0);

adapter = new FullScreenImageAdapter(FullScreenViewActivity.this,


// displaying selected image first

private View insertPhoto(final String path) {

final Bitmap bm = decodeSampledBitmapFromUri(path, 220, 220);

LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new LayoutParams(250, 250));

ImageView imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new LayoutParams(220, 220));

// imageView.setId(i);
// iView.setId(i);
// viewPager.setId(i);

imageView.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
int id = v.getId();




return layout;

public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth,
int reqHeight) {

Bitmap bm = null;

// First decode with inJustDecodeBounds=true to check dimensions final
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(path, options);

return bm;
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!