Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加scrollview的加载更多 #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 62 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
[![Android Gems](http://www.android-gems.com/badge/liaohuqiu/android-cube-app.svg)](http://www.android-gems.com/lib/liaohuqiu/android-cube-app)

##### 欢迎关注我

Github: https://github.com/liaohuqiu

twitter: https://twitter.com/liaohuqiu

blog: http://liaohuqiu.net

微博: http://weibo.com/liaohuqiu

---


[![Build Status](https://travis-ci.org/liaohuqiu/android-cube-app.svg?branch=master)](https://travis-ci.org/liaohuqiu/android-cube-app)

这个项目的目的是作为一个APP开发参考。

#### 功能点

* 加载更多
<div class='row'>
<img src='http://srain-github.qiniudn.com/load-more/load-more-for-list-view.gif' width="300px" style='border: #f1f1f1 solid 1px'/>
<img src='http://srain-github.qiniudn.com/load-more/load-more-for-grid-view.gif' width="300px" style='border: #f1f1f1 solid 1px'/>
</div>


### 依赖

* support-v4, 版本: r7
* clog, 版本: 1.0.2, https://github.com/liaohuqiu/android-CLog
* cube-sdk, 版本: 1.0.44.33-SNAPSHOT, https://github.com/etao-open-source/cube-sdk
* ultra-pull-to-refresh, 版本: 1.0.9.1-SNAPSHOT, https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
* eventbus, 版本: 2.4.0, https://github.com/greenrobot/EventBus

### 关于Eclipse运行项目

通过gradle(Android Studio / Intellij IDEA)以及maven可以无阻碍地运行项目。但对于eclipse的同学来说,可能会遇到一些障碍。

一些依赖,直接是jar包, (support-v4, clog, event-bus), 我都放在了libs目录下,直接引入到工程即可。

另外依赖的一些项目因为含有资源文件,无法仅打包成jar, 需要打包成aar或者apklib,而Eclipse是没有办法直接使用这两种格式的。

建议:将这些依赖的类库的项目在Eclipse作为工程打开,引入到你的项目中。以下是需要引入的项目:

* cube-sdk. https://github.com/etao-open-source/cube-sdk core文件夹作为一个类库项目引入

* ultra-ptr. https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh. ptr-lib文件夹,作为一个类库项目引入。

注意: **请使用dev分支中最新的代码**

### 联系方式和问题建议

* 微博: http://weibo.com/liaohuqiu
* 博客: http://www.liaohuqiu.net
* QQ 群: 271918140
* [email protected]
* twitter: https://twitter.com/liaohuqiu
[![Android Gems](http://www.android-gems.com/badge/liaohuqiu/android-cube-app.svg)](http://www.android-gems.com/lib/liaohuqiu/android-cube-app)

##### 欢迎关注我

Github: https://github.com/liaohuqiu

twitter: https://twitter.com/liaohuqiu

blog: http://liaohuqiu.net

微博: http://weibo.com/liaohuqiu

---


[![Build Status](https://travis-ci.org/liaohuqiu/android-cube-app.svg?branch=master)](https://travis-ci.org/liaohuqiu/android-cube-app)
### 添加scrollview的加载更多功能
必须引用https://github.com/qs-lll/cube-sdk
更改cube- sdk 源码

这个项目的目的是作为一个APP开发参考。

#### 功能点

* 加载更多
<div class='row'>
<img src='http://srain-github.qiniudn.com/load-more/load-more-for-list-view.gif' width="300px" style='border: #f1f1f1 solid 1px'/>
<img src='http://srain-github.qiniudn.com/load-more/load-more-for-grid-view.gif' width="300px" style='border: #f1f1f1 solid 1px'/>
</div>


### 依赖

* support-v4, 版本: r7
* clog, 版本: 1.0.2, https://github.com/liaohuqiu/android-CLog
* cube-sdk, 版本: 1.0.44.33-SNAPSHOT, https://github.com/etao-open-source/cube-sdk
* ultra-pull-to-refresh, 版本: 1.0.9.1-SNAPSHOT, https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
* eventbus, 版本: 2.4.0, https://github.com/greenrobot/EventBus

### 关于Eclipse运行项目

通过gradle(Android Studio / Intellij IDEA)以及maven可以无阻碍地运行项目。但对于eclipse的同学来说,可能会遇到一些障碍。

一些依赖,直接是jar包, (support-v4, clog, event-bus), 我都放在了libs目录下,直接引入到工程即可。

另外依赖的一些项目因为含有资源文件,无法仅打包成jar, 需要打包成aar或者apklib,而Eclipse是没有办法直接使用这两种格式的。

建议:将这些依赖的类库的项目在Eclipse作为工程打开,引入到你的项目中。以下是需要引入的项目:

* cube-sdk. https://github.com/etao-open-source/cube-sdk core文件夹作为一个类库项目引入

* ultra-ptr. https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh. ptr-lib文件夹,作为一个类库项目引入。

注意: **请使用dev分支中最新的代码**

### 联系方式和问题建议

* 微博: http://weibo.com/liaohuqiu
* 博客: http://www.liaohuqiu.net
* QQ 群: 271918140
* [email protected]
* twitter: https://twitter.com/liaohuqiu
7 changes: 7 additions & 0 deletions src/in/srain/cube/demo/ui/loadmore/LoadMoreHomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public void onClick(View v) {
getContext().pushFragmentToBackStack(LoadMoreGridViewFragment.class, null);
}
}));
itemInfos.add(newItemInfo(R.string.cube_demo_load_more_grid_view, "#4d90fe", new OnClickListener() {

@Override
public void onClick(View v) {
getContext().pushFragmentToBackStack(LoadMoreScrollViewFragment.class, null);
}
}));
}

@Override
Expand Down
127 changes: 127 additions & 0 deletions src/in/srain/cube/demo/ui/loadmore/LoadMoreScrollViewFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package in.srain.cube.demo.ui.loadmore;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.ListView;
import in.srain.cube.demo.R;
import in.srain.cube.demo.base.DemoTitleBaseFragment;
import in.srain.cube.demo.data.ImageListItem;
import in.srain.cube.demo.datamodel.ImageListDataModel;
import in.srain.cube.demo.event.DemoSimpleEventHandler;
import in.srain.cube.demo.event.ErrorMessageDataEvent;
import in.srain.cube.demo.event.EventCenter;
import in.srain.cube.demo.event.ImageListDataEvent;
import in.srain.cube.demo.ui.viewholders.ImageListItemSmallImageViewHolder;
import in.srain.cube.image.ImageLoader;
import in.srain.cube.image.ImageLoaderFactory;
import in.srain.cube.util.LocalDisplay;
import in.srain.cube.views.list.PagedListViewDataAdapter;
import in.srain.cube.views.loadmore.CubeScrollView;
import in.srain.cube.views.loadmore.LoadMoreContainer;
import in.srain.cube.views.loadmore.LoadMoreHandler;
import in.srain.cube.views.loadmore.LoadMoreListViewContainer;
import in.srain.cube.views.loadmore.LoadMoreScrollViewContainer;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

public class LoadMoreScrollViewFragment extends DemoTitleBaseFragment {

private ImageListDataModel mDataModel;
private ImageLoader mImageLoader;
private PtrFrameLayout mPtrFrameLayout;
private CubeScrollView mCubeScrollView;

@Override
public View createView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

setHeaderTitle(R.string.cube_demo_load_more_scroll_view);

mImageLoader = ImageLoaderFactory.create(getContext()).attachToCubeFragment(this);

// set up data
mDataModel = new ImageListDataModel(5);


// set up views
final View view = inflater.inflate(R.layout.fragment_load_more_scroll_view, null);

// pull to refresh
mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.load_more_list_view_ptr_frame);

mPtrFrameLayout.setLoadingMinTime(1000);
mPtrFrameLayout.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {

// here check list view, not content.
return PtrDefaultHandler.checkContentCanBePulledDown(frame, mCubeScrollView, header);
}

@Override
public void onRefreshBegin(PtrFrameLayout frame) {
mDataModel.queryFirstPage();
}
});

// list view
mCubeScrollView = (CubeScrollView) view.findViewById(R.id.load_more_small_image_scroll_view);
for (int i = 0; i < 25; i++) {
Button button = new Button(getActivity());
button.setText(""+i);
((ViewGroup)mCubeScrollView.getChildAt(0)).addView(button);

}

// header place holder
View headerMarginView = new View(getContext());
headerMarginView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LocalDisplay.dp2px(20)));

// load more container
final LoadMoreScrollViewContainer loadMoreListViewContainer = (LoadMoreScrollViewContainer) view.findViewById(R.id.load_more_list_view_container);
loadMoreListViewContainer.useDefaultHeader();

// binding view and data
loadMoreListViewContainer.setLoadMoreHandler(new LoadMoreHandler() {
@Override
public void onLoadMore(LoadMoreContainer loadMoreContainer) {
mDataModel.queryNextPage();
}
});

// process data
EventCenter.bindContainerAndHandler(this, new DemoSimpleEventHandler() {

public void onEvent(ImageListDataEvent event) {

// ptr
mPtrFrameLayout.refreshComplete();

// load more
Button button = new Button(getActivity());
loadMoreListViewContainer.loadMoreFinish(mDataModel.getListPageInfo().isEmpty(), mDataModel.getListPageInfo().hasMore());
button.setText(((ViewGroup)mCubeScrollView.getChildAt(0)).getChildCount()-1+"");
((ViewGroup)mCubeScrollView.getChildAt(0)).addView(button,((ViewGroup)mCubeScrollView.getChildAt(0)).getChildCount()-1);
}

public void onEvent(ErrorMessageDataEvent event) {
loadMoreListViewContainer.loadMoreError(0, event.message);
}

}).tryToRegisterIfNot();

// auto load data
mPtrFrameLayout.postDelayed(new Runnable() {
@Override
public void run() {
mPtrFrameLayout.autoRefresh(false);
}
}, 150);

return view;
}
}