PullToRefresh Gridview on android scroll when refreshing - android

I use Chris Banes's PullToRefresh library. PullToRefreshGridview works fine, but there is a problem. When refreshing, the gridview locked, it can't move. I set ptrScrollingWhileRefreshingEnabled as true, the gridview can scroll while refreshing, but the refreshing view is always there, it cannot hide or get smaller like PullToRefreshListview does.
How can I fix it, makes the PullToRefreshGridview works like PullToRefreshListview?

You need to call "onRefreshComplete" method.
for example..
#Override
public void onPullDownToRefresh(PullToRefreshBase refreshView) {
refreshView.onRefreshComplete();
}

Related

Adding Custom Animation when Removing Item RecyclerView

I would like to show a custom animation to match the other animations that I have in my RecyclerView. I can’t find a straight forward way of adding custom animations for removal. I know that when RecyclerView replaced ListView one of the talking points was the ability to know when items are added or removed rather than simply saying the dataset has changed and updating everything, so I figured there would be an easy way to add an animation to a View when it is removed that I am missing.
When I add an animation to a view that is removed the animation will not play. This is likely because the View is removed and the animation stops. Is there an easy way to add an animation to a View that doesn’t get cut off? I'm assuming that I could use a second thread, but I want to know if I am missing something.
//code for removal
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//animation to be added here on view
list.remove(holder.getAdapterPosition());
notifyItemRemoved(position);
notifyItemRangeChanged(position,list.size()-position);
}
});
All add/change/delete/move animations in recyclerView are made by ItemAnimator (by default animator is DefaultItemAnimator). So if you need custom delete animation you should provide custom ItemAnimator via recyclerView.setItemAnimator(animator) method.
I suggest to extend from SimpleItemAnimator and override animateRemove method.

Etsy Staggered gridview android smoothScrollToPosition

I have to implement a smoothScrollToPosition with Eatsy Staggered gridview but the Gridview method doesn't work. How can I do a method that simulate the smooth scroll to a specific cell?
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
if(*myCondition*){
adapter.notifyDataSetChanged();
gridView.smoothScrollToPosition(position);
}
}
}
With standard GridView smoothScrollToPosition works fine, not works with Staggered.
gridView.setSelection(position);
not work correctly, the cells change their position and if I scroll the grid manually restore their correct position (with standard grid view works fine, so I think the problem isn't my code but the library)
Late response but I think you'd be better off using RecyclerView with StaggeredManager: http://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html

Resize ListView Element While Viewing in Android?

What I am trying to do is populate a listView with views/elements that could be a textview/imageview. Potentially, these textviews are expandable. I want the listview to resize and wrap the content if the textview is expanded.
There are several solutions out there already:
1. Make the elements of the ListView element invisible so that the view in ListView is already the size you want. In this case, create the text view with the original long string and then collapse it.
2. Resize the element in the adapter then call notifyDataSetChanged();
However I'm looking for a solution where the view in ListView automatically resizes, even when its visible. I have tried using Solution #2 and while it works for changing values inside the view such as a string, it doesn't resize the view altogether unless the view is scrolled off screen then comes back into view.
The relevant part of my code is as follows:
holder.text.setTrim(!holder.text.getTrim());
holder.text.setText();
holder.text.requestFocusFromTouch();
notifyDataSetChanged();
holder.text.invalidate();
vi.invalidate();
vi.requestLayout();
I put this inside an OnClickListener inside an adapter's getView function.
Anyone have any solutions?
PS. Has anyone tried doing a method with multiple adapters? This one doesnt seem to work too well for me because I have potentially hundreds of elements.
Edit:
So I've come up with part of a stupid solution that is absolutely ridiculous. The behavior makes no sense. Below (primaryTextView is the same text as above eg. holder.primaryTextView == holder.text)
holder.primaryTextView.setTrim(!holder.primaryTextView.getTrim());
if(!holder.primaryTextView.getTrim()){
holder.primaryTextView.setVisibility(View.GONE);
}
else{
holder.primaryTextView.setVisibility(View.VISIBLE);
}
notifyDataSetChanged();
vi.invalidate();
This allows you to expand the view while viewing it but does not allow you to shrink the view once the text is collapsed. Furthermore, View.GONE and View.VISIBLE are NOT interchangable. Finally, the textView does not even dissapear in the event that View.GONE is triggered. Perhaps this might be a clue?
it doesn't resize the view altogether unless the view is scrolled off screen then comes back into view.
It is working, but you are not refreshing the listview, when you scroll off & return, listview recreates the updated view.
You should notifyDataSetChanged(); adapter.notifyDataSetChanged();
Nevermind found the problem:
In my layout, I was using height="0dp" instead of "wrap_content"

button at bottom of list view is now showing up [duplicate]

I have a ListView declared inside a layout. When I addFooterView(v) it does NOT display. What are the possible reasons for this? Is there some setting in ListView or my Adapter to make this display immediately? It does eventually display but only after reinitializing the view, adapter and all.
Update: It seems that resetting the adapter finally makes it appear .... Obviously not something that I should have to do everytime I call addFooterView(v).
The view containing the ListView is inside a View maintained by PageViewer so not sure if that effects this or not.
Add the footer view before you set the adapter is the only thing we can replicate with when we are not able to see your code.

android ListView ,setSelection() has no effect after setFlags(...FULLSCREEN)

Now I have this problem when:
In my Asynctask, I have a ProgressDialog over this Listview that is constantly updated and scrolling automatically (I use something like mListview.setSelection(mData.size()-1); to scroll it )
I want it to be fullscreen when it's not finished or canceled, which I think is pretty easy by Window dialogWindow = mProgressDialog.getWindow();
dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
I also want it to stop being fullscreen( i.e. I want the status bar shown) when it's finished. And I want the first item in the Listview shown as well.
-------------------- This 's when the problem occurrs.--------------------
I use like
dialogWindow.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
and it's working well. The status bar appears.
then I use mListview.setSelection(0), which I suppose can bring the me first item.
HOWEVER, it has no effect at all. Any idea how this happens or how to solve it? Any help would be greatly appreciated. Thank you!
you can try this method, it maybe helpful to you..
http://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int)
public void smoothScrollToPosition (int position)
Since: API Level 8
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Parameters
position Scroll to this adapter position.
You have to use
mListview.clearFocus();
before calling
mListview.requestFocusFromTouch();
mListview.setSelection(0);
in a post method of mListView.

Categories

Resources