How can you retreive images from firebase and display in gridview android - java

I created a listview and recycler/card view with firebase no problem, but I cannot do a gridview involving pictures using picasso library. I have been trying for 3 days now.
Can someone point me in the correct direction? I can't seem to find any tutorials or videos on such process...
Thank you in advance.

I hope this process will work for you.
Define GridView in your layout like this
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"></GridView>
Create an adapter inflating layout like this,
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="fitXY"/>
Fetch ImageUrl from firebase add in arraylist and provide that arraylist to adapter.
get that imageUrl from arrylist and set to the imageview in adpter by using picasso.

Related

How to make scrollable long image page?

I am making activity showing TOS(Terms of Service) contents.
TOS text content is written very long single image, which should be scrolled. And confirm button is located below it.
Is there any best practice to make it?
I used ScrollView to scroll contents.
ScrollView contains ImageView and ImageButton.
First, I insert very long TOS content image by android:src attribute.
But, xxxhdpi image file is about 1MB size and height is about 18000 thus the app crashed (it shows 'canvas trying to draw too large bitmap' error)
After that, I try using image library which are Glide and Picasso. Using them, the error doesn't occur but image quality got degraded.
I searched and tried many solution to keep resolution and render speed but failed.
I think trying to use smaller image is better solution, but in emulator scroll speed and behavior was very strange when used src attribute to draw image.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<FrameLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
<ImageButton
android:id="#+id/textview"
some code... />
</FrameLayout>
</ScrollView>
I am not sure if using single long image with scrollView to show TOS contents is correct or not. And not sure if it is possible to handle long image properly with ImageView.
Respectfully, you're making life difficult for yourself.
Having the TOS in image form only is unusual; the 'correct' approach is to have your TOS in text form, which would also be fastest to code.
If the TOS is composed elsewhere, and you don't wish to re-type it, then possibly feed the image to an online OCR service and see what comes back?
Alternately, use a WebView component connecting to a web server serving a page with only the TOS image. (But this is a bad idea, because now you'll need to set-up and maintain a web-server!)
Try to put image to drawable-nodpi folder
If you are using Glide try to use .thumbnail() attr
Add to Android manifest largeHeap attr
And at least decrease size of big image

Make infinite scrollable ImageViews

I'm making an app which allows a user to search the various countries. The user can make filtered searches (such as, for example, search only countries of a specific continent, etc...). All this info (Countries and their continents are stored in my Firebase Realtime Database).
In my FilteredResults.java fragment I want to have a variable number of ImageViews (the number of the size of a List<String>).
This sketch I drew might help you understand it better:
Each one of this rectangles are ImageViews.
This is my XML (I just have a scrollview because I don't know how to create an "array" of ImageViews...)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtResultadosFiltrados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="28dp"
android:layout_marginTop="0dp"
android:text="Resultados Filtrados"
android:textColor="#323B45"
android:textSize="24sp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="28dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</RelativeLayout>
In order to solve your problem in an optimal way, you should use one of:
a plain old ListView,
a newer, more powerful RecyclerView.
These views support so called adapters which map between a model (in your case: List<String>) and a list of items (in your case a list of ImageView's).
Here you have a complete example of a simple app which loads lists of posts from the Firebase Database:
https://github.com/firebase/quickstart-android/tree/master/database
This example is based on RecyclerViews, you can find an a direct usage here:
https://github.com/firebase/quickstart-android/blob/master/database/app/src/main/java/com/google/firebase/quickstart/database/fragment/PostListFragment.java
Use RecyclerView instead of ScrollView. As keeping array of ImageView and adding them in a ScrollView will create a explosive headache.

ViewPagerIndicator - Set the TabPageIndicator to the center

I make an timetable application for android and I'm using ViewPagerIndicator as fragment. But now I've a problem, I want to get the TabPageIndicator to the center. Like this:
And I would to like to set the individual tab width and height. And set that tab to a drawable that support selected/pressed states.
I've not found it yet to solve these problems. I've try something with onPageSelected and ContextThemeWrapper but that doesn't work. (Maybe I'm not using it correctly).
Is this all possible to make or should I look to something else than ViewPagerIndicator? (An other option without ViewPagerIndicator is also welcome).
The app on the image is Untis Mobile and can be found on the PlayStore.
I've already ask the creators how they do it but they said the app isn't open source. (But I have found in the source that they do it with TwoDScrollView, but I'm not sure)
Edit:
The styling is fixed with vpiTabPageIndicatorStyle. (With help of XDA Developers!)
When I add 20 items it stays on the middle but only from item 4 to item 17, item 1, 2, 3, 18, 19, 20 are not in the middle. See:
Can I add a 3 empty items (or empty space) to ensure that the first and last items are in the middle? Something like this (from the Untis Mobile app):
(I've already tried android:paddingLeft in vpiTabPageIndicatorStyle but that doesn't work)
I know that viewPager.setCurrentItem(total/2) will set the TabPageIndicator in the middle but then it stays on the middle and I'm not able to select a other day (I call it in onPageScrolled). So I want as you scroll the selected one needs to be in the middle. Is this possible?
The widget you are looking for is similar to the android horizontal wheel. There is an implementation at android-spinnerwheel which can be what you need.
Then you don't need an viewpagerindicator. Use a horizontal scroll view as Amulya Khare suggested in your activity and replace fragments when scrolling occurs.
Your activity layout could be like :
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SomeWheelView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<SomeStaticIndicatorView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
Set a listener to wheelview and when change occurs you can put your fragments in framelayout in your activity.
Use it like this :
TabPagerIndicator tbi;
ViewPager pager;
in onCreate() do like this
tbi=(TabPagerIndicator)findViewById(R.id.something);
tbi.setViewPager(pager);
I hope this will work out for you. :D

Pinterest Style in Displaying Images with UIL

Pinterest Style of Displaying Images is exceptional, and this adds beauty to your app. After a couple of research I found out that there are great libraries out there that can display images like Pinterest do but not sure if this is compatible with UIL.
I am using the Universal-Image-Loader in displaying my images. In the image shown below I got my images displayed in that manner with some views together with it. It is undeniably true that UIL library handles phone memory greatly in displaying a lot the images. I'd like to know if it is possible to display my images like the Pinterest's but still using UIL as the generator. What are the possible resolve to this approach? Or maybe another library that only handles the display and compatible with UIL.
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:horizontalSpacing="4dip"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="4dip"
android:padding="4dip" />
Update:
I tried using the StaggeredGridView but the layout can't be cast to GridView.
<com.origamilabs.library.views.StaggeredGridView
xmlns:tools="http://schemas.android.com/tools"
xmlns:staggered="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
staggered:numColumns="3"
staggered:drawSelectorOnTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Hey Check out my implementation of Pinterest type view using Staggered GridView and Universal-Image-Loader here.

Styling the android listview with array list adapter

I have written the code for creating a list out of some arrays shown below!
code runs properly and output is as expected!
update for people with same prob: nice tutorial for custom listview
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView1 = (ListView) findViewById(R.id.listView1);
String[] items = { "some", "fancy", "items", "to", "show" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.listitem, items);
listView1.setAdapter(adapter);
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ListView
android:id="#+id/listView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
</RelativeLayout>
listview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="22dp"
android:gravity="center_horizontal"
/>
what I want to accomplish?
change color and font of the text in each list item to a different one..and do some task on tapping on them...
also is it possible to get another listview inside the same listview
eg. if I click on a list item it again shows me a list (kind of a sub list) with different list items on that same activity(or screen).and some action could be done on tapping the sub list items.
Detailed answers are appreciated as I am new to android development..
Thanks!
1.change color and font of the text in each list item to a different one..and do some task on
tapping on them...
Make a Custom Adapter, override getVIew() of that adapter and make
changes on color and text in it.
override onItemClick() for your ListView. to accomplish click event
for list item.
Now
2. also is it possible to get another listview inside the same listview eg. if I click on a
list item it again shows me a list (kind of a sub list) with different list items on that
same activity(or screen).and some action could be done on tapping the sub list items.
3. what are my other list styling options..
Its a Expandable ListView Just look at link for more
information.
And Tutorial
You'll want to look into a custom ArrayAdapter as seen here http://www.vogella.com/articles/AndroidListView/article.html
That will take care of the first and third questions. As for the second one that's not possible with the default implementation of ListView but there are libraries that enable you to create drop down listItems.
For 1st question, you can use paulthom12345' answer.
2nd question: You have to use exapandableListView
for more details please see: Android ExpandableListView - Looking for a tutorial
3rd question is not constructive and very vague. Please edit the question and explain in greater detail.
Use Customized List View for it.
It is not exactly possible to have a list inside a list. Instead of it, use expandable list
Have a look at Android Listview with different layout for each row

Categories