How to share image intent with viewpager? - android

I need to develop an application, where I need to be able to share image from ImageView in ViewPager when user press on Share Button.
My problem:
when Ipress on Share Button the ImageView cache the next Image not the current .
public class MainActivity extends Activity {
private ViewPager pager;
private ImageView Imgv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
final Integer[] imageUrls={
R.drawable.img1 , R.drawable.img2 , R.drawable.img3 , R.drawable.img4
};
pager.setAdapter(new MyAdapter(imageUrls));
Button share = (Button) findViewById(R.id.share);
share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Imgv.setDrawingCacheEnabled(true);
Bitmap icon = Imgv.getDrawingCache();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
Uri uri = Uri.parse("file:///sdcard/temporary_file.jpg");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(shareIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private class MyAdapter extends PagerAdapter {
private LayoutInflater inflater;
private Integer[] fimg;
public MyAdapter(Integer[] fimg ) {
this.fimg=fimg;
inflater = getLayoutInflater();
}
#Override
public Object instantiateItem(View collection, int position ) {
final View imageLayout = inflater.inflate(R.layout.imgview, null);
Imgv = (ImageView)imageLayout.findViewById(R.id.full_image_view);
Imgv.setBackgroundResource(fimg[position]);
((ViewPager) collection).addView(imageLayout ,0);
return imageLayout;
}
#Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return super.getItemPosition(object);
}
#Override
public int getCount() {
return fimg.length;
}
#Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
// TODO Auto-generated method stub
return view==((View)object);
}
#Override
public void restoreState(Parcelable arg0, ClassLoader loader) {}
#Override
public Parcelable saveState() {
return null;
}
#Override
public void startUpdate(View container) {
}
#Override
public void finishUpdate(View container) {
}
}
}

It is because you think that Imgv is ImageView from current visible page in ViewPager. But it isnt. In your case Imgv is ImageView from the last inflated page, but not the current visible page.
I suggest you to add tag to ImageView:
Imgv.setBackgroundResource(fimg[position]);
Imgv.setTag(position); // add this line
Then you can find your ImageView by tag:
ImageView Imgv = (ImageView)pager.findViewWithTag(pager.getCurrentItem());
Imgv.setDrawingCacheEnabled(true);
...

To avoid using the drawing cache which may sometimes mean a downscaled image, I'd check out the onPageSelected() event of the ViewPager onPageChange listener.
Save the current index, and create the file to be saved from your original asset.

The Simplest and best way to get the images is by using http://developer.android.com/reference/android/support/v4/view/ViewPager.html#getCurrentItem()
This will give you the index of the current page which is nothing but the index of the imageUrls which has the current image.
So get your bitmap from imageUrls using BitmapFactory.
BitmapFactory.decodeResource(getResources(), imageUrls[pager.getCurrentItem()]);

Related

Android InvalidStateException on ViewPager when setting page limit too small

I have a problem with my ViewPager Image slider gallery. I am setting my page limit to 3 but then my app craches on the third image because the child has already a parent. I set the limit to this number because I want to avoid large memory leaks, event with 3 images it uses up like 150Mb of allocated memory which is incredibly huge ammount. Maybe if I resize the image before uploading I can get them to work with more pages ? Anyways, here is my code for the viewPager:
ViewPager mViewPager = (ViewPager) findViewById(R.id.imagepager);
ViewerAdapter adapter = new ViewerAdapter(this);
//adapter.notifyDataSetChanged();
mViewPager.setAdapter(adapter);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setCurrentItem(number);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
time.setText(caluculateTimeAgo(MainActivity.time[position]));
if (MainActivity.distances[position] < 1000) {
dist.setText(String.valueOf(MainActivity.distances[position]) + "m");
} else {
long f = (long) (MainActivity.distances[position] / 1000);
dist.setText(String.valueOf(f) + "km");
}
author.setText(MainActivity.users[position]);
text.setText(MainActivity.text1[position]+MainActivity.tags[position]);
}
#Override
public void onPageSelected(int position) {
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
and here is my adapter definition:
public class ViewerAdapter extends PagerAdapter {
Context mContext;
public ViewerAdapter(Context context) {
mContext = context;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
LayoutInflater mLayoutInflater;
#Override
public int getCount() {
return MainActivity.imgLink.length;
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == (View) arg1;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
Picasso.with(container.getContext()).cancelRequest((ImageView) object);
}
#Override
public CharSequence getPageTitle(int position) {
return (position + "/" + getCount());
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
final View itemView = mLayoutInflater.inflate(R.layout.pager_item,container,false);
final ImageView photo = (ImageView) itemView.findViewById(R.id.photoSlide);
photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fullscreen = ((BitmapDrawable)photo.getDrawable()).getBitmap();
Intent intent = new Intent(ShowMarkerContent.this, FullScreenImageActivity.class);
startActivity(intent);
}
});
Picasso.with(container.getContext()).load("MyWebsite" + MainActivity.imgLink[position]).into(photo);
container.addView(photo);
return photo;
}
}
Well, I managed to make a work-around for this problem. I forgot to set the cropping of the photo and therefore the photos were too large for this. And also, I set the offScreenPageLimit to 30 to avoid this error (This is that work-around because with large quantity of image it will come to out of memory error) So now, here is my adapter code:
#Override
public Object instantiateItem(ViewGroup container, int position) {
final View itemView = mLayoutInflater.inflate(R.layout.pager_item,container,false);
final ImageView photo = (ImageView) itemView.findViewById(R.id.photoSlide);
photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fullscreen = ((BitmapDrawable)photo.getDrawable()).getBitmap();
Intent intent = new Intent(ShowMarkerContent.this, FullScreenImageActivity.class);
startActivity(intent);
}
});
Picasso.with(container.getContext()).load("MyWebsite" + MainActivity.imgLink[position]).fit().centerCrop().into(photo);
container.addView(itemView);
return itemView;
}

how to share images using view pager

public class EyeLinerActivity extends Activity {
int position;
private ShareActionProvider provider;
ELImageAdapter adapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eyeliner);
//ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
//adapter = new ELImageAdapter(this);
//viewPager.setAdapter(adapter);
//ViewPager.setCurrentItem(0);
ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
adapter = new ELImageAdapter(this);
pager.setAdapter(new ELImageAdapter(this));
// ImageView imageView = new ImageView(context);
// imageView.setImageResource(GalImages[position]);
// if (pager.getAdapter() != null)
// pager.setAdapter(adapter);
// pager.setCurrentItem(position);
}
#SuppressLint("NewApi")
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem shareitem= (MenuItem)menu.findItem(R.id.action_share);
ShareActionProvider provider = (ShareActionProvider)shareitem.getActionProvider();
Bitmap bitmap;
OutputStream output;
//ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
bitmap = BitmapFactory.decodeResource(getResources(),adapter.GalImages[position]);
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/Eye Liner/");
dir.mkdirs();
File file = new File(dir, "Image.png");
try {
Intent share = new Intent(Intent.ACTION_SEND);
share.setAction(Intent.ACTION_SEND);
share.setType("image/jpeg");
output = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
Uri uri = Uri.fromFile(file);
share.putExtra(Intent.EXTRA_STREAM, uri);
provider.setShareIntent(share);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
//return super.onCreateOptionsMenu(menu);
private void setShareIntent(Intent intent) {
if (provider != null) {
provider.setShareIntent(intent);
}
}
}
adapter.java
public class ELImageAdapter extends PagerAdapter {
Context context;
public int[] GalImages = new int[] {
R.drawable.l_1,
R.drawable.l_2,
R.drawable.l_3,
R.drawable.l_4,
R.drawable.l_5,
R.drawable.l_6,
R.drawable.l_7,
R.drawable.l_8,
R.drawable.l_9,
R.drawable.l_10,
R.drawable.l_11,
R.drawable.l_12,
R.drawable.l_13,
R.drawable.l_14,
R.drawable.l_15,
R.drawable.l_16,
R.drawable.l_17
};
ELImageAdapter(Context context){
this.context=context;
}
#Override
public int getCount() {
return GalImages.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
i want to share images .. and i am using viewpager
how can i get images ids to share.? as viewpager does not support onclickitemlistener property. kindly suggest how i can get image id to dhare
If you implement a FragmentStatePagerAdapter, each page of your ViewPager can host an instance of a Fragment of your design, with its layout defined in XML. This will allow you to include whatever Views you need to compose your custom sharing UI.
From Creating Swipe Views with Tabs | Android Developers:
FragmentStatePagerAdapter
This is best for paging across a collection of objects for which the number of pages is undetermined. It destroys fragments as the user navigates to other pages, minimizing memory usage.
For example, here's how you might use FragmentStatePagerAdapter to swipe across a collection of Fragment objects:
public class CollectionDemoActivity extends FragmentActivity {
// When requested, this adapter returns a DemoObjectFragment,
// representing an object in the collection.
DemoCollectionPagerAdapter mDemoCollectionPagerAdapter;
ViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_collection_demo);
// ViewPager and its adapters use support library
// fragments, so use getSupportFragmentManager.
mDemoCollectionPagerAdapter =
new DemoCollectionPagerAdapter(
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mDemoCollectionPagerAdapter);
}
}
// Since this is an object collection, use a FragmentStatePagerAdapter,
// and NOT a FragmentPagerAdapter.
public class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter {
public DemoCollectionPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
Fragment fragment = new DemoObjectFragment();
Bundle args = new Bundle();
// Our object is just an integer :-P
args.putInt(DemoObjectFragment.ARG_OBJECT, i + 1);
fragment.setArguments(args);
return fragment;
}
#Override
public int getCount() {
return 100;
}
#Override
public CharSequence getPageTitle(int position) {
return "OBJECT " + (position + 1);
}
}
// Instances of this class are fragments representing a single
// object in our collection.
public static class DemoObjectFragment extends Fragment {
public static final String ARG_OBJECT = "object";
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
View rootView = inflater.inflate(
R.layout.fragment_collection_object, container, false);
Bundle args = getArguments();
((TextView) rootView.findViewById(android.R.id.text1)).setText(
Integer.toString(args.getInt(ARG_OBJECT)));
return rootView;
}
}
In your case you could change share intent on every page selected event, like following:
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int i, float v, int i2) {
}
#Override
public void onPageSelected(int i) {
setShareIntentForPosition(i);
}
#Override
public void onPageScrollStateChanged(int i) {
}
});
private void setShareIntentForPosition(int currentPosition){
Bitmap bitmap;
OutputStream output;
bitmap = BitmapFactory.decodeResource(getResources(),adapter.GalImages[currentPosition]);
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/Eye Liner/");
dir.mkdirs();
File file = new File(dir, "Image.png");
try {
Intent share = new Intent(Intent.ACTION_SEND);
share.setAction(Intent.ACTION_SEND);
share.setType("image/jpeg");
output = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
Uri uri = Uri.fromFile(file);
share.putExtra(Intent.EXTRA_STREAM, uri);
setShareIntent(share);
}
private void setShareIntent(Intent intent) {
if (provider != null) {
provider.setShareIntent(intent);
}
}
how can i get images ids to share.?
Use ViewPager.getCurrentItem() to get current image id from ViewPager:
1. Create a method in ELImageAdapter class to get current selected image id :
public int getImageId(int pos){
return GalImages[pos];
}
2. Call getImageId method using adapter object in onCreateOptionsMenu method :
int currentPos=pager.getCurrentItem();
int currentImgId=adapter.getImageId(currentPos);
Now use currentImgId id to share selected image.
File file = new File(adapter.images.get(myPager.getCurrentItem()));
Intent mShareIntent = new Intent(Intent.ACTION_SEND);
mShareIntent.setType("image/*");
mShareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file));
startActivity(Intent.createChooser(mShareIntent,"Shareith:"));
Where adapter is object of CustomAdapter creating pages for viewpager, myPager is reference variable for ViewPager enter code here and images is arraylist storing imagepath.

How to use URI's with an imageAdapter

I have an ArrayList of Uri's that i want to display in a ViewPager,
this is how my code looks, I have both shown how i have put the URi into a bitmap and a drawable:
public class ImageViewActivity extends Activity {
private List<String> selectedItems;
private Uri uri1;
private Drawable drawable1;
private Bitmap bitmap1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_view);
ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(new TouchImageAdapter());
selectedItems = new ArrayList<String>();
Intent intent = getIntent();
selectedItems = intent.getStringArrayListExtra("selectedItems");
Log.d(ImageViewActivity.class.getSimpleName(), "" + selectedItems.get(0));
uri1 = Uri.parse( selectedItems.get(0));
try {
InputStream inputStream = getContentResolver().openInputStream(uri1);
drawable1 = Drawable.createFromStream(inputStream, uri1.toString());
} catch (FileNotFoundException e) {
drawable1 = getResources().getDrawable(R.drawable.image_for_empty_url);
}
Bitmap myBitmap = BitmapFactory.decodeFile(selectedItems.get(0));
bitmap1 = myBitmap;
}
static class TouchImageAdapter extends PagerAdapter {
private static int[] images = {};
#Override
public int getCount() {
return images.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
TouchImageView img = new TouchImageView(container.getContext());
img.setImageResource(images[position]);
container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
return img;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
}
but the refference code i'm looking at, has it in the "Drawable Resource Folder", code looks like this:
public class ViewPagerExampleActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewpager_example);
ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(new TouchImageAdapter());
}
static class TouchImageAdapter extends PagerAdapter {
private static int[] images = { R.drawable.nature_1, R.drawable.nature_2, R.drawable.nature_3, R.drawable.nature_4, R.drawable.nature_5 };
#Override
public int getCount() {
return images.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
TouchImageView img = new TouchImageView(container.getContext());
img.setImageResource(images[position]);
container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
return img;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
}
I want to use each of my URI's in the ImageAdapter, i just can't figure out how to "put them into" the ImageAdapter.
First of all get the absolute path of image from Uri Because we can not convert image into bitmap using image Uri ,so just with the help of following code you can get Absolute path
Uri ImageURI = "your image uri goes here";
String selectedImagePath = ImageFilePath.getPath(getApplicationContext(), ImageURI);
File imageFile = new File(selectedImagePath);
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
then set image bitmap in the ImageView
imageView.setImageBitmap (bitmap);
hopefully this will solve your problem.

get image file name in view pager

I'm displaying images from resource/drawable folder in full screen using viewpager. It's working fine and are sliding well. now i want to save image name in sdcard,but i am not able to get image file name. if any one will please help me . I have google it, i didn't get correct solution for my expection.
code
public class MainActivity extends Activity{
//private static Context context;
ExtendedViewPager mViewPager;
private static Uri imageUri;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(new TouchImageAdapter());
}
static class TouchImageAdapter extends PagerAdapter {
private static int[] images = { R.drawable.nature_1, R.drawable.nature_2, R.drawable.nature_3, R.drawable.nature_4, R.drawable.nature_5 };
}
#Override
public int getCount() {
return images.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
//Context context = container.getContext();
TouchImageView img = new TouchImageView(container.getContext());
img.setImageResource(images[position]);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int imagid=images[position];
System.out.println("Image name " + images[position]);
bm = BitmapFactory.decodeStream(v.getResources().getDrawable(imagid));// here i need to pass my resId, i can't able to pass
}
});
//img.setScaleType(TouchImageView.ScaleType.CENTER_CROP);
container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
return img;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
}
create a String[] which contains file name and set it's itme to img as tag and in onClick get the tag. do something like this
private static String[] imagesName = {"fiel1","file2",.....};
.
.
img.setImageResource(images[position]);
img.setTag(imagesName[position]);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String filename = v.getTag().toString();
}
}
Edit
If you don't want to create String[] then set the images[position] as Tag of img and in onClick get it from tag like getResources().getResourceName((Integer)v.getTag());
This helps me.

how can i get the right value and set in text view with image pager adapter?

What I have is a class called FullImageActivity2 which displays images and I can flip between images with a pager adapter also in this activity I have a TextView which should display an item id for each image and it takes it values from a string array. I could connect the TextView with the value but the value does not change when I flip the image, I mean that I want each image to be connected with it's id and when I flip the image it should change and display the correct image.
here is my activity code :
public class FullImageActivity2 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_image_activity2);
String[] nameArray={"Su6670","SU10670","PB6670","PB10670"};
TextView itemid=(TextView)findViewById(R.id.itemid);
//get intent data
//Selected image id
Integer[] newArray={R.drawable.bottle1,R.drawable.bottle2,R.drawable.bottle3,R.drawable.bottle4};
ImageAdapter imageAdapter = new ImageAdapter(this, newArray);
List<ImageView> images = new ArrayList<ImageView>();
for (int i1 = 0; i1 < imageAdapter.getCount(); i1++) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(imageAdapter.mThumbIds[i1]);
itemid.setText(nameArray[i1]);
images.add(imageView);
}
// Finally create the adapter
ImagePagerAdapter imagePagerAdapter = new ImagePagerAdapter(images);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setAdapter(imagePagerAdapter);
for (int m=0; m<imagePagerAdapter.getCount();m++){
itemid.setText(nameArray[m]);
}
}
}
and here is the image pager adapter code :
public class ImagePagerAdapter extends PagerAdapter{
private List<ImageView> images;
public ImagePagerAdapter(List<ImageView> images) {
this.images = images;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = images.get(position);
container.addView(imageView);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(images.get(position));
}
#Override
public int getCount() {
return images.size();
}
#Override
public boolean isViewFromObject(View view, Object o) {
// TODO Auto-generated method stub
return view == o;
}
}
it always display the value PB10670 in the TextView. How can I fix this problem?
You have to set a OnPageChangeListener to your ViewPager like
viewPager.setOnPageChangeListener(new OnPageChangeListener()
{
#Override
public void onPageSelected(int arg0)
{
itemid.setText(nameArray[arg0]);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
}
#Override
public void onPageScrollStateChanged(int arg0)
{
}
});
This way whenever you flip your image the text in your TextView will change depending on the current position.

Categories

Resources