Coder Social home page Coder Social logo

Comments (7)

erikwt avatar erikwt commented on September 28, 2024

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.

vincentjames501 avatar vincentjames501 commented on September 28, 2024

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.

erikwt avatar erikwt commented on September 28, 2024

Yes, you are right. I'm re-opening the issue and will look into it ASAP.

from pulltorefresh-listview.

vincentjames501 avatar vincentjames501 commented on September 28, 2024

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.

tagrudev avatar tagrudev commented on September 28, 2024

a pull request >?

from pulltorefresh-listview.

erikwt avatar erikwt commented on September 28, 2024

A pull request would be nice...

from pulltorefresh-listview.

Joohansson avatar Joohansson commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.