Skip to content

Commit

Permalink
解决条目少时的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
limxing committed Mar 17, 2016
1 parent 0188926 commit 61d92f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/limxing/xlistview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ public class MainActivity extends AppCompatActivity implements XListView.IXListV
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

listview=(XListView) findViewById(R.id.listview);
listview.setPullLoadEnable(true);
listview.setXListViewListener(this);

listview.setAdapter(new BaseAdapter() {
@Override
public int getCount() {
return 20;
return 3;
}

@Override
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/com/limxing/xlistview/view/XListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class XListView extends ListView implements OnScrollListener {

// -- footer view
private XListViewFooter mFooterView;
private boolean mEnablePullLoad;
private boolean mEnablePullLoad=false;
private boolean mPullLoading;
private boolean mIsFooterReady = false;

Expand Down Expand Up @@ -117,9 +117,11 @@ public void onGlobalLayout() {
mFooterView.findViewById(R.id.xlistview_footer_hint_textview).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
mPullLoading = true;
mFooterView.setState(XListViewFooter.STATE_LOADING);
startLoadMore();
if(!mPullLoading&&!mPullRefreshing) {
mPullLoading = true;
mFooterView.setState(XListViewFooter.STATE_LOADING);
startLoadMore();
}
}
});
}
Expand Down Expand Up @@ -315,16 +317,16 @@ public boolean onTouchEvent(MotionEvent ev) {
// the first item is showing, header has shown or pull down.
updateHeaderHeight(deltaY / OFFSET_RADIO);
invokeOnScrolling();

} else if (!mPullRefreshing && getLastVisiblePosition() == mTotalItemCount - 1
&& (mFooterView.getBottomMargin() > 0 || deltaY < 0)) {
// last item, already pulled up or want to pull up.
updateFooterHeight(-deltaY / OFFSET_RADIO);

}
break;
case MotionEvent.ACTION_UP:

mLastY = -1; // reset

if (!mPullRefreshing && getFirstVisiblePosition() == 0) {
// invoke refresh
if (mEnablePullRefresh
Expand All @@ -336,7 +338,8 @@ public boolean onTouchEvent(MotionEvent ev) {
}
}

} else if (!mPullLoading && getLastVisiblePosition() == mTotalItemCount - 1) {
}
if (!mPullLoading && getLastVisiblePosition() == mTotalItemCount - 1) {
// invoke load more.
if (mEnablePullLoad
&& mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA
Expand Down

0 comments on commit 61d92f6

Please sign in to comment.