String Image Url set in imageview Android - android

I Need a help for My First develop android app. I want to set a image with the help of url in my ImageView which is coming from google Api. I have a listView in Which the data are coming from google apis. in Listview, I implement a image with the help of picasso android libruary. I am using a fragment when the user click on each list item from listView. On CLick of listItem I am opening a fragment on Which I need To display a data of list Item.
For ListView, I am using a userDefined List in which the images are of type
In DetailFragment where I want to display the details I am using the below Source Code.
#Override
public void findViewById() {
foodtitle=(TextView)mView.findViewById(R.id.detail_foodtext);
foodsubtitle=(TextView)mView.findViewById(R.id.detail_foodsubtext);
foodresImage=(ImageView)mView.findViewById(R.id.detail_image_left);
foodaddress=(TextView) mView.findViewById(R.id.detail_foodaddress);
Bundle b=getArguments();
b.getString("ItemName");
b.getString("ItemSubItem");
b.getInt("ItemImage");
b.getString("ItemAddress");
foodtitle.setText(b.getString("ItemName"));
foodsubtitle.setText(b.getString("ItemSubItem"));
foodresImage.setImageResource(b.getInt("ItemImage"));
foodaddress.setText(b.getString("ItemAddress"));
}
on This place
foodresImage.setImageResource(b.getInt("ItemImage"));
I want my Image which is one imageView in detail Fragment.

Since you are using Picasso then you should use it like:
Picasso.with(getContext()).load(fb.getString("ItemImage")).into(foodresImage);
You are using fb.getInt() in your setImageResource and you are getting a string from the Google API. You cannot convert the link to an int resource.

Related

How add photo to recycleview using Android kotlin firebase

Using Android kotlin firebase recycle view
I want to make the user take a picture of his phone or get a photo from gallery and add it to recyclerView list , and every time he takes a photo the recycler list increase automatically it works if i get the photo from drawable now i want to get it from camera or gallery. how to achieve it thanks
Please refer to the documentation https://developer.android.com/guide/topics/ui/layout/recyclerview, under section Add a list adapter you can read a following information :
To feed all your data to the list, you must extend the RecyclerView.Adapter class. This object creates views for items, and replaces the content of some of the views with new data items when the original item is no longer visible.
So, basically you have to create adapter for your recycler view, from which you can insert new item (photo) to you recyclerview.
More information about implementation the functionality is here:
How to update RecyclerView Adapter Data?
To capture/select photo from your gallery first you need permission accessing internal/external storage and camera I suggest you to read this https://developer.android.com/training/permissions/requesting
If you are willing to use Firebase to get these drawable/imgs, so you've to get the URL of the image as a string and put it in ArrayList/List.
Then your adapter class get URL and then use bitmap to download the image and convert it to bitmap (data type), How to load an ImageView by URL in Android?
Now when retrieving data from fire base: https://firebase.google.com/docs/database/admin/retrieve-data
add the string you got from the database in your arraylist then usenotifyOnDataChanged() to update your recyclerview.
How to update RecyclerView Adapter Data?

Android Gallery objects obtained from network to Individual gallery object

GridGalleryThumbnailFragment to photoActivity
All the gallery objects are obtained from internet, my current setup is whenever user reaches the Fragment a network request is made and if it successful the gallery objects with thumbnails and image urls are returned. When the user clicks on an individual item a intent will start the activity and puts extra intent data with image title and image url and the image is opened in full screen. Now I want to implement a next/previous functionality in the Activity, what is the best approach for it.
Make a second network request in the activity and get the values from this new adapter.
Remove the activity workflow and just replace View in the fragment with the full image view.
Store all the values obtained the first time around in android local storage.
You need two adapters which have the same data in the same order:
a GalleryAdapter and a ImagePagerAdapter
When the GalleryView starts the ImageView the ImageView needs the gallery-s current offset. next/previous is just adding 1 to or subtracting 1 from the offset.
I have implemented something similar but based on a database query using a CursorAdapter and a android.support.v4.view.PagerAdapter . Both GalleryView and ImageView share the same sql.
[Update]
If you donot want to load the data twice you can use a LoaderManager where GalleryView and ImageView both use the same loader-Impementation/loader-ID

String array of image URL in Android GridView

I have an array of photos that has been filled with url obtained from webservice.
Now i want to display the photos into a gridview, but i can seem to understand how you do it..
This is the code that i have simplified:
public GridView grid1;
public String photos[];
grid1 = (GridView)root.findViewById(R.id.gridphotos);
grid1.setAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,photos ));
grid1.setTextFilterEnabled(true);
But it only appears the links text....
Can i use WebView to fill the adapter?
Thanks
You need to create your own adapter either by extending ArrayAdapter or BaseAdapter.
Check out the sample here.. http://www.learn-android-easily.com/2013/09/android-custom-gridview-example.html

ArrayAdapter : Custom array adapter for list view with image view keeps loading wrong images

I have a Custom Array Adapter For a list view that contains an Image View. In the custom adapter class I have an asynctask that Downloads a unique picture from a unique url of each item in the list . The problem is the ImageViews for each item keeps changing pictures continously . Please what is there any problem with getting Images from urls through an AsyncTask in a custom array adapter class .
Help is needed (In any form)
Take a look of those libraries that can help you :)
Picasso
Universal Image Loader
The problem with starting an asynchronously loading things for a ListView (or any other adapter sourced view) is that Views can get reused once they are off the screen. The easiest way to deal with this is to use a library to do it for you, my favorite is AQuery
If you don't want to go that route, you'll have to role your own. To do this, you will need to check if the view at the completion of the AsyncTask is showing the same stuff as when it started. Call setTag(tag) on the View you're returning in the adapter's getView(). Then before you set the image to the ImageView, call getTag() on the view and check it equals the same object as what you set it as. It should look something like this:
final View view = MY VIEW;
final Object tag = new Object();
view.setTag(tag);
new AsyncTask() {
...
public void onPostExecute(Bitmap bar) {
if(tag.equals(view.getTag()) {
imageView.setImage(bar);
}
}
...
}.execute();
return view;
And then you can start caching and things like that. Complex right? So yeah, you should use a library.

How to send Listview item data (image & text) from one activity to another activity in android

I am working on application in which user will be able to retrieve data from weburl using json and i have made that module, but now i want to show selected listview item in another activity using intent in which i have to show them Image and Text of selected Item...could you please show me some source code or way to write the code for the same one.
If you're inflating a view from JSON data, couldn't you just send the JSON string as an extra with the activity intent, and the inflate the view inside the second activity?
For example,
Intent.putExtra("json",mJson);
where mJson is the name of your string object containing the JSON. Then in your other activity's onResume, do something like
mJson = getIntent().getExtras().getString("json");
And then inflate the view using that JSON string.
You can not simply add image into your bundle.you can add your text simply like
Intent.putExtra("text",yourText);
To add image into bundle refer this,
how do you pass images (bitmaps) between android activities using bundles?
You have to use parceble object within bundle.

Categories

Resources