How to maintain sticky gridview in Android - android

I want to implement the sticky gridview in my application but the problem is that my header of the gridview is also move when I scroll the gridview, So could you please help me to sort out from these problem

You can check out StickyGridHeaders is library that provides a GridView that shows items in sections with headers. By default the section headers stick to the top like the People app in Android 4.x but this can be turned off.
StickyGridHeaders also automatically sizes its rows to the largest item in the row.
Another is AStickyHeader for adding Sticky Headers to ListView or GridView.
Hope this will help you.

TonicArtos's repo is great, but I found it hard to integrate it with my app. Also, I couldn't get the example code to run so I decided to fork it and improve it a little bit.
The only thing that was added was 2 classes that makes the creation of the adapter a lot easier IMO.
The first of those classes is:
public abstract class UtilAdapter<T, VH extends BaseViewHolder> extends BaseAdapter {
//methods to add and remove elements & viewholder implementation
}
This class provides some methods to add and remove elements from an internal list it has (kind of what ArrayAdapter does). It also implements the viewholder pattern for you so you just have to implement a few abstract methods.
The second class is:
public abstract class StickyGridAdapter<T, VH extends BaseViewHolder, HVH extends BaseViewHolder> extends UtilAdapter<T, VH> implements StickyGridHeadersSimpleAdapter {
//viewholder imlpementation for the header view (also has abstract methods)
}
This class implements StickyGridHeadersSimpleAdapter (TonicArtos's interface). It also implements the viewholder pattern for the header views, so extending this class makes you implement a few methods that return ViewHolder classes and other methods that populate said viewholders.
To implement a sticky header grid you just have to extend StickyGridAdapter, use StickyGridHeadersGridView instead of GridView in your layout and set the adapter as usual.
Here is a link to the repo (which is a fork of TonicArto's):
https://github.com/OneCodeLabs/StickyGridHeaders
I also wrote some example code using my classes. I hope it can help you

Related

customlayout as mvp in fragment mvp

I've been practising the MVP pattern in android.
My question is related to how to design the situation where you have a fragment with a custom layout.(see the below layout)
customlayout in fragment
There are 2 cardviews in the customlayout:
- if you click on the friends cardview, a dialogfragment will be displayed showing a customadapter whose data comes from fetching the local DB
- if you click on the others cardview, a dialogfragment will be displayed showing a customadapter whose data comes from a server.
You can check the people in this adapter and if you click OK, the images of the checked people will be displayed in the cardview
I have made the fragment a view as part of an MVP construct but I got stuck.
Is it a good idea to create the customlayout as an MVP construct as well? or not just the layout, but the cardviews, too?
And if yes, then these "nested" MVPs how would they send the data(the friends & the others) back to the host fragment/presenter when I click the Save Button?
Or am I overcomplicating this simple fragment-layout architecture?
Any suggestions are appreciated
The fragment implements the below View:
public interface CreateEventContract {
interface View extends BaseView<Presenter>{
void showStartDateDateDialog();
void showStartDateTimeDialog(LocalDate selectedDate);
void showPlaceMapActivity();
void saveButtonClicked();
boolean isActive();
}
interface Presenter extends BasePresenter {
void startDateDateDialog();
void startDateTimeDialog(LocalDate selectedDate);
void place();
void saveEvent();
}
}
and the CustomLayout:
customLayout gist
In that situation, I think one could be guided by the tablet MVP example on GitHub, the Android Architecture Blueprints.
Transferred to your case, your structure could be something like this
The views are reporting (e.g who's been checked) to a common Presenter, who is manipulating the views through their particular Presenter.

Android Recyclerview, want to know how it determines the data list for listing

So I am trying to figure out how to use RecyclerView for listing items.
Unlike ListView which has an adapter that passes list to its constructor for the internal working, RecyclerView does not seem to have one,
for example, in a class extending RecyclerView.Adapter
We provide contructor to set list we declared.
public CustomAdapter(Data[] myDataset) {
this.mDataset = myDataset;
}
but how does RecyclerView.Adapter exactly know what to use?
for example, since the constructor is provided by us, it is possible that we make a contructor with put two parameters with two different data type lists/arrays.
Then how will the adapter know which list to use??
add: or does it use according to how you use your lists on onBingVIewHolder method? if so, then how does position parameter work?
Take a look at this post. It has a very simple example with a pretty good overview/explanation of the recyclerview and how it works.

Populating ListView from Database without Using SimpleCursorAdapter

I have a seperate DatabaseHandler("db") Class which extends SQLiteOpenHelper BUT NOT ACTIVITY which means this is a seperate class file which is not related to any activity. If you ask why i have such a class not in activity because i like keeping my files organized.
So i have listview in a fragment and i have a "DatabaseHandler.getAllRows()" function in that class which returns a "List" Object. Then i want to use this list to populate my listview.
So when this class is a seperate class which is not related to any activity, i can't use simplecursorAdapter since it wants a context in paramteres part when creating with new(i tried to send parameter as context but didnt work) so i need to use something else....
I can change return type, i can use another thing instead of listview.. just give me a good advice for how to populate listview or show table rows NICELY.
If you want a real simple solution, you can store your rows as an array, and use ArrayAdapter to display them. You can override the getView to display the results in your preferred way.
If this solution is not good enough, I think you will have to implement your own Adapter, which might be a good idea anyway.

StableArrayAdapter vs ArrayAdapter

I am looking at this ListView Tutorial:
ListView Tutorial
and I was wondering how much better is to create my own ArrayAdapter, rather than just using and ArrayAdapter.
In the Tutorial it defines a "StableArrayAdapter", what exactly does this means? If I use a regular ArrayAdapter, could it be dangerous for some reason?
The two previous answers are absolutely right, but just to address more directly your question and in case someone else has the same doubt than you; a regular ArrayAdapter is not dangerous at all, the only "problem" is that it might not fulfill your needs, in which case you will have to create your own adapter, as the author of the tutorial did by creating what he called StableArrayAdapter in the end of the ListViewExampleActivity class.
Don't get lost by the name, which I guess comes from the fact that the overwritten method "hasStableIds" always returns true, it doesn't mean that the regular ArrayAdapter creates problems.
ArrayAdapter: It is merely a way to provide data to a ListView. It is also a BaseAdapter that is backed by an array of objects.
CustomAdapter: If if your ListView is a normal and simple ListView (wherein you are having one TextView per item in the list), then the use of ArrayAdapter would be apt.
But it is recommended you to create your own CustomAdapter which extends an ArrayAdapter that you can use for providing data to your ListView. This way you can easily extend your ListView to include more that one TextView or even ImageView (to show images).
CursorAdapter: Cursor Adapter is used when you have Data in a Cursor (typically when you are retrieving data from a database. The Cursor must include a column named "_id" or this class will not work.
If you are using a simple ListView, like merely a TextView per item, then just use the standard ArrayAdapter, on the other hand, if you want a custom item in the list, as in a combinations of views within each item in the ListView, then extend the ArrayAdapter and implement it to your needs.
StableArrayAdapter is merely an extended version of ArrayAdapter, but in StableArrayAdapter they have overridden the method hasStableIds() of BaseAdapter to return true.
You can check this in the following links:
StableArrayAdapter -
Override hasStableIds to return true
ArrayAdapter -
Has not Override hasStableIds but extended BaseAdapter
BaseAdapter -
Has hasStableIds but returning false
Now Question is What is the use of StableIds
This Indicates whether the item ids are stable across changes to the underlying data. If True then same id always refers to the same object. for more info

Display GridView inside ExpandableListView for unknown groupCount in Android

I'm having a class (ExpandableListDataClass) which extends BaseExpandableListAdapter
I am calling to ExpandableListDataClass from an Activity like below;
ExpandableListDataClass expandableListDataClass = new ExpandableListDataClass(this, categories);
categoryExpandableListView.setAdapter(expandableListDataClass);
categories is a String array. That means groupCount of the ExpandableListDataClass is depend on the categories.
The worst thing is, I am loading a GridView for expanding of a group item in ExpandableListView. Those GridView have different data to show according to the category.
If I use following code inside getChildView(), it is perfectly working
if(getGroup(groupPosition).toString().equals("ebooks")){
expandableListInsideGridView.setAdapter(eBooksImageAdapterForExpandableList);
}else if(getGroup(groupPosition).toString().equals("ebrochures")){
expandableListInsideGridView.setAdapter(eBrochuresImageAdapterForExpandableList);
}
But what I want to remove from that is eBooksImageAdapterForExpandableList and eBrochuresImageAdapterForExpandableList. Because now what I am doing is creating ArrayList according to the existing categories.
But when I don't know how many categories/groupCount there are, I can't do that.
Please give me a solution
Finally I was able to find a solution :-)
I will explain it in backwards.
In the getChildView() I have to give following line of code
expandableListInsideGridView.setAdapter(new ImageAdapterForExpandableList(expandableListDataClassContext, eItemThumbCachePathArrayListContainer.get(groupPosition), eItemNamesArrayListContainer.get(groupPosition), eItemUrlArrayListContainer.get(groupPosition)));
getChildView() is in the ExpandableListDataClass which extends the BaseExpandableListAdapter.
What I had to do is declare an ArrayList which contains some other ArraLists of same type. If I explain it more with my code eItemThumbCachePathArrayListContainer is an ArrayList which contains ArrayLists of type String that I want to pass. That is the simple logic I have used and it works for me.

Categories

Resources