Comments (7)
The PullToRefreshListView does not override #setEmptyView of ListView, so you can just use http://developer.android.com/reference/android/widget/AdapterView.html#setEmptyView(android.view.View) or set the empty view in XML like you would on any other regular ListView.
from pulltorefresh-listview.
I have to agree that this is a bug. When using setEmptyView, you lose the functionality to pull to refresh when the list is indeed empty. Also it is very gltchy when refreshing (as the list goes empty for a brief second while updating and you see the empty view).
from pulltorefresh-listview.
Yes, you are right. I'm re-opening the issue and will look into it ASAP.
from pulltorefresh-listview.
I thought I'd just go ahead and put my solution:
In PullToRefreshListView add the following:
private TextView emptyView;
private String noItemsText;
public void removeEmptyHeaderView() {
if(getHeaderViewsCount()!=1) {
removeHeaderView(emptyView);
}
}
//modify
public void onRefreshComplete() {
state = State.PULL_TO_REFRESH;
if (emptyView != null) {
if (getAdapter().isEmpty()) {
if (getHeaderViewsCount() == 1) {
emptyView.setHeight(getHeight());
emptyView.setText(noItemsText);
addHeaderView(emptyView);
}
} else {
if (getHeaderViewsCount() == 2) {
removeHeaderView(emptyView);
}
}
}
resetHeader();
}
//in init() add
noItemsText = getContext().getString(R.string.ptr_no_items_text); //modify string xml file
emptyView = buildDefaultEmptyView();
//add this method - this can be refactored to use styles
private TextView buildDefaultEmptyView() {
TextView emptyView = new TextView(getContext());
emptyView.setText(noItemsText);
emptyView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.FILL_PARENT));
emptyView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL);
emptyView.setTextColor(Color.BLACK);
emptyView.setTextSize(20);
return emptyView;
}
public void setNoItemsText(String noItemsText) {
this.noItemsText = noItemsText;
}
public void setEmtpyView(TextView view) {
this.emptyView = view;
}
This can be refactored but simply gives a default empty view with a modifiable TextView
from pulltorefresh-listview.
a pull request >?
from pulltorefresh-listview.
A pull request would be nice...
from pulltorefresh-listview.
I need the setEmptyView functionality and would be really happy if it´s solved. The solution vincentjames501 provided works, but not initially. The list is empty from the beginning and the text is not shown until a refresh is done. I want to tell the user that he needs to refresh. I tried to call the onRefreshComplete() manually but it will not update the header for some reason?
from pulltorefresh-listview.
Related Issues (20)
- Flicker when setAdapter HOT 1
- Place listView below another view HOT 1
- animation "stutters" if listview has padding HOT 3
- when the listview is refreshing I can not click the item to turn to another activity
- Divider appears before the first item HOT 3
- ClassCastException preventing PullToRefreshListView from inflating
- eu.erikw.PullToRefreshListView failed to instantiate
- Customize the distance from when "Release to refresh" is showed
- PullToRefresh_ListView in ViewPager HOT 2
- "Pull to refresh" banner disappears if I scroll to the bottom of the list HOT 1
- bouncing animation problem
- PullToRefresh banner gets locked when scrolling quickly HOT 1
- ListView not Visible entire list items (or) some items are not completely displayed HOT 2
- Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.RelativeLayout HOT 1
- java.lang.IllegalStateException HOT 4
- setOnItemClickListener has the wrong position. HOT 3
- ptr_header.xml should include layout_width/layout_height or it will cause exception
- How to use with listfragment
- PTRListView below other layouts
- Pull to left or right and show icon from left or right
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pulltorefresh-listview.