Android: Display images in full screen mode using Picasso - android

Hi i have some images displayed in gridView using Picasso, when i try to open each image (after onItemClickListener) in full screen mode (inside new acivity) it display only the first image in my gridView whatever the image i click, this is my problem.
This is my code where i display the images from the url inside gridView and OnItemClickListener.
Picasso.with(ToolDescription.this)
.load(SaveSettings.ServerURL +"Images/"+ imagepath)
.into(imageView);
ls.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ToolDescription.this, ImageFull.class);
intent.putExtra("imagepath", SaveSettings.ServerURL +"Images/"+ imagepath);
startActivity(intent);
}
});
return myView;
This is my second activity (named ImageFull) where i want to display the clicked image:
ImageView imageView = (ImageView) findViewById(R.id.fullImage);
String imagepath = getIntent().getStringExtra("imagepath");
Picasso.with(ImageFull.this)
.load(imagepath)
.noFade()
.resize(800, 800)
.centerCrop()
.into(imageView);

Either set an individual click listener to each imageview or use the int position to pull the correct imagepath from your gridview item array.
Grid View Android Doc
This link has a easy to follow code for exactly what you're trying to do.. Use the position to find which element you are clicking on an get the respective image url

Looks like what's happening is that you're calling ls.setOnItemClickListener() every time getView() returns.
AdapterView.OnItemClickListener is a single listener for the entire AdapterView, and you're intended to differentiate which item was clicked on by using its position argument.
I'm not sure where imagepath is coming from inside getView(), but I assume it's something like String imagepath = getItem(position).getImagePath(). If that is the case, you can fix your problem by:
1) Move ls.setOnItemClickListener() out of getView()... probably to your onCreate() or whever you set up your GridView.
2) Change
intent.putExtra("imagepath", SaveSettings.ServerURL +"Images/"+ imagepath);
to
String currentImagePath = getItem(position).getImagePath();
intent.putExtra("imagepath", SaveSettings.ServerURL +"Images/"+ currentImagePath);
Probably there will be syntax errors because I can't see the rest of your code, but hopefully this is enough for you to be able to work through them.

Related

How to Send Jpg Image from one activity to another activity in android?

Hope You Are Fine
Well am stuck in a little bit of problem...I have a main activity in which i am using custom listview(showing movie_poster,movie_name,movie_rating)...and i want that if i click on a row a new activity should be open and jpeg image (movie_poster)in that row should be show in other activity...i tried a lot of things but could not find a solution..
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent=new
Intent(MainActivity.this,Description_Activity.class);
int index= (int)parent.getItemIdAtPosition(position);
String description=movie_descriptions[index];
intent.putExtra("title",movie_titles[index]);
intent.putExtra("rating",movie_ratings[index]);
intent.putExtra("desc", description);
startActivity(intent);
}
});
You can't send Image it self you have to send Image URL, Resource ID, or path from SD Card.
When you click on row Send Image path to activity using intent.
intent.putExtra("title",movie_titles[index]);
intent.putExtra("rating",movie_ratings[index]);
intent.putExtra("desc", description);
intent.putExtra("resourseInt", R.drawable.image);
startActivity(intent);
On Second activity
int res = extras.getInt("resourseInt");
ImageView view = (ImageView) findViewById(R.id.something);
view.setImageResourse(res);
Where is the image coming from? If its a url pass the url or its its coming from local disk, then pass the disk path:
intent.putExtra("image",<your_url_or_path>);
And then use this url or path in your second activity to show the image wherever you want to show it.

Different Images for each listview item in android

I am building my first app. I want to display a different image for every listview item when I click on it. Can anyone please help me out?
This is the way that I tried in the calling activity.
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
locationListView.buildDrawingCache();
Bitmap image = locationListView.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
Intent intent;
intent.putExtras(extras);
startActivity(intent);
Bundle extra = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
image.setImageBitmap(bmp);
}
Have you tried anything yet?
Take a look at these tutorials
http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/
http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92
These will help you accomplish the required task.
Its not much different than creating a regular list view. you just need to modify row.xml file and there are multiple ways to load data into the listview eg JSON array or pull from databaseas explained here http://www.edumobile.org/android/android-programming-tutorials/learn-how-to-create-listview-from-sqlite-database-in-android-development/
Let me know if it works out in the comments , or if u need any additional help

Android listview toggle image by click, changes more than one image

I have a listview and on click I try to change an arrow image inside my listview adapter row.
This works fine, but I have the problem, that not only a single image changes. A few rows above and below the arrow images also change.
It changes the images in every 6th row.
the code for my onClick event is this:
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent,View view, int position, long id) {
if (row != null)
{
ImageView PfeilImage = (ImageView) row.findViewById(R.id.imageView1);
PfeilImage.setImageResource(R.drawable.pfeil);
}
ImageView PfeilImage2 = (ImageView) view.findViewById(R.id.imageView1);
PfeilImage2.setImageResource(R.drawable.pfeil_aktiv);
row = view;
getInfoById(position);
}
});
It would be nice if someone could help me with that problem.
thanks in advance
Frank
That's actually normal for how the ListView is setup since it is designed to not re-inflate Views, but instead re-use them; which is why you can't just change the image, you need to change the data it's pointing to.
The solution to this, inside your Adapter's getView() method, is to check the data and set the background image based on that.
You may want to create a new Class to hold your current data and the new image to use holder. ie.
Class ListViewItem
-int imageToUse
-Object whateverDataYouWereOriginallyUsing
and then set the image for that view based on ListViewItem.get(position).imageToUse
Now, when you're actually changing the data based on a user click, you'll need to call notifyDataSetChanged() on the adapter so that it will re-evaluate the UI based on the new DataSet and your getView() method
got it, many thanks.
in my Adapter Class I made a new int variable "myClickedPosition".
In my click event I set this variable and after this I set notifyDataSetInvalid to redraw the listview:
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> theAdapter,View view, int position, long id) {
LazyAdapter mAdapter = (LazyAdapter) theAdapter.getAdapter();
mAdapter.myClickedPosition=position;
mAdapter.notifyDataSetInvalidated();
getInfoById(position);
}
});
and in my getView function I check the clicked position:
if(myClickedPosition == position)
{
PfeilIcon.setImageResource(R.drawable.pfeil_aktiv);
} else {
PfeilIcon.setImageResource(R.drawable.pfeil);
}
Now all is working fine.

android gallery scroll like view pager

I have used both Gallery and ViewPager widgets, I am fetching images from web service,
but I couldn't place them in the ViewPager, but in Gallery it is easy.
I used this tutorial for ViewPager
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/
I want android Gallery widget scroll like the ViewPager scroll,
is this possible, how can I do this.
Here is a bare bones example of the instantiateItem() method for your PagerAdapter that would fill it with image views dynamically.
#Override
public Object instantiateItem( final View pager, final int position )
{
//Note: if you do not have a local reference to the context make one and
//set it to the context that gets passed in to the constructor.
//Another option might be to use pager.getContext() which is how its
//done in the tutorial that you linked.
ImageView mImg = new ImageView(context);
/*Code to dynamically set your image goes here.
Exactly what it will be is going to depend on
how your images are stored.
In this example it would be if the images
are on the SD card and have filenames
with incrementing numbers like: (img0.png, img1.png, img2.png etc...)*/
Bitmap mBitmap = BitmapFactory.decodeFile(
Environment.getExternalStorageDirectory() + "/img" + position + ".png");
mImg.setImageBitmap(mBitmap);
((ViewPager) collection).addView(mImg, 0);
return mImg;
}

Android GridView - update View based on position

I have a GridView, using a custom adapter (myAdapter extends BaseAdapter), where each item in the grid holds an ImageButton. getView() is working fine.
However, from elsewhere in my code, how can I update the image (setImageResource) for one particular item in the grid based on its position in the GridView?
So far, I've added this to my adapter class:
public void changeImage() {
Log.d(TAG, "Image change");
this.ImageButton.setImageResource(R.drawable.newImage);
}
And would like to write something like this: mygridview.getItemIdAtPosition(20).changeImage(); (doesn't compile).
If u want to update the image for one particular item in the grid, what u can do is...have an onClickListener for all the images in the grid.
Now when u will click on any of the image, get the position of the image and change ur background resource for that particular image.
Example:
While adding the image: imageView.setOnClickListener(imageListener);
And the listener will be something like dis:
private OnClickListener imageListener = new OnClickListener() {
public void onClick(View v) {
int id = v.getId();
ImageView imgView = imageArray.get(id);
imgView .setBackgroundResource(R.drawable.newImage);
};
I hope u find it helpful.
In case of Images in a GridView I did this and it works also:
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View imgView, int position, long id) {
ImageView imageView = (ImageView) imgView;
imageView.setImageResource(R.drawable.newImage);
}
}); }
That's also my last problem. Here my solution I use data Model and adapter for my RecyclerView
Firstly, register your new data to your model
DataModel detail = new DataModel(id, name, sat, image);
after that, use set to replace old value with the new one
mData.set(index, detail);
finally, refresh your adapter
if(adapter!=null)
adapter.notifyItemChanged(index);

Categories

Resources