• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen_view);

viewPager = (ViewPager) findViewById(R.id.pager);
myGallery = (LinearLayout) findViewById(R.id.mygallery);
scrollView = (HorizontalScrollView) findViewById(R.id.horizontal1);
scrollView.setBackground(getResources().getDrawable(R.drawable.border));
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory().getAbsolutePath();

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

files = targetDirector.listFiles();

for (File file : files) {

myGallery.addView(insertPhoto(file.getAbsolutePath()));

}

utils = new Utils(getApplicationContext());

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

adapter = new FullScreenImageAdapter(FullScreenViewActivity.this,
utils.getFilePaths());

viewPager.setAdapter(adapter);

// displaying selected image first
viewPager.setCurrentItem(position);
}

private View insertPhoto(final String path) {

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

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

ImageView imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new LayoutParams(220, 220));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(bm);

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

imageView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
int id = v.getId();
viewPager.setCurrentItem(id);

}

});

layout.addView(imageView);

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,
reqHeight);

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

return bm;
}
}
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic