0

I have a gridView set up in android that I am using to display Videos along with 2 different lines of text, which is all going smoothly and running fine. However when I went to add the footer such as I had done with ListViews, it doesn't appear to be an option. I have found other results on StackOverflow but they all end in the same result with the footer always being on the screen such as the footer in the Instagram app. I need a solution that will display below all of the rows such as ListView.addFooter(view_footer) would offer, in the sense of the location. I already have my footer's XML that I have used in my other activities.

How do I add an XML view below the rows in a gridView?

EDIT 01/05/14 3:28PM

I had an idea that if i set up another custom row, and another custom adapter, that i could add my footer in that type of way, but I don't think there can be 2 adapters.

inVINCEable
  • 2,167
  • 3
  • 25
  • 49
  • You cannot add a Header/Footer to a `GridView` as you saw there are no methods for it. you might be able to find a third party library that does it but nothing in the Android SDK lets you do this to a gridview – tyczj Jan 05 '15 at 19:58
  • Is there a workaround that you have found? preferably without 3rd party libraries. I've been attempting different solutions with no luck – inVINCEable Jan 05 '15 at 20:01
  • No I used a third party library then gave up on it because it was not worth it. You cold try using `RecyclerView` and implementing something similar to a question I asked here http://stackoverflow.com/questions/26568087/parallax-header-effect-with-recyclerview – tyczj Jan 05 '15 at 20:02
  • Have you checked out http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.3_r2.1/com/android/photos/views/HeaderGridView.java Basic idea is to trick getCount(), and give it +1*columns. And then when that getView is called give the header instead. – mlaHackingIsMagic Jan 05 '15 at 20:13
  • http://stackoverflow.com/questions/5790215/can-a-gridview-have-a-footer-and-header-just-like-listview – corsair992 Jan 05 '15 at 20:57

1 Answers1

0

Using a third Party Library it can be easily done using this Github Project

To get it running in your project, start by importing it into your build.gradle by adding this line:

compile 'in.srain.cube:grid-view-with-header-footer:1.0.9'

into your dependencies

Secondly go to your XML where you have your <GridView> and substitute it for <in.srain.cube.views.GridViewWithHeaderAndFooter>

Next go to your .java class where your grid view is set up and replace This

GridView gridView;

With this

GridViewWithHeaderAndFooter gridView;

And replace this line:

gridView = (GridView) findViewById(R.id.theGrid); 

with this

gridView = (GridViewWithHeaderAndFooter) findViewById(R.id.theGrid);

.

Finally The most important part add your header or footer using the following:

LayoutInflater inflater = LayoutInflater.from(this);
View footer = inflater.inflate(R.layout.footer_layout, null);
gridView.addFooterView(footer);

BELOW THIS gridView = (GridViewWithHeaderAndFooter) findViewById(R.id.theGrid);

AND ABOVE THIS gridView.setAdapter(grisViewCustomeAdapter);

inVINCEable
  • 2,167
  • 3
  • 25
  • 49