BaseAbsActivity的使用
来源:互联网 发布:中文域名有什么价值 编辑:程序博客网 时间:2024/06/07 11:17
首先,是布局的设置。
PullToRefreshListView的id约定为pull_to_refresh_adapter_view,不能设置为其他。无数据布局的id约定为custom_empty_view,框架通过对两个控件的显示和隐藏来达到数据列表和无数据提示的页面切换动作。如果无需显示无数据提示页面,那么就不需要写custom_empty_view的布局。
<com.u1city.module.pulltorefresh.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/pull_to_refresh_adapter_view" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@null" android:dividerPadding="0dp" android:fadingEdge="none" android:listSelector="@android:color/transparent" android:orientation="vertical" android:scrollbars="none" android:overScrollMode="never" ptr:ptrShowIndicator="false" ptr:ptrAnimationStyle="flip" />
<include android:id="@+id/custom_empty_view" layout="@layout/empty_view_custom_default" android:visibility="gone" />
然后,是控件和设置的初始化。
我们通过明确泛型的类型来确定列表的类型,我们的Ptr兼容了当前需要用到的列表,包括ListView,GridView,HeadableGridView,瀑布流StaggeredGridView,滑动菜单列表SwipeMenuListView,PinnedHeaderListView等,简化了上拉下拉动作需要处理的代码,简化了数据填充的代码量。
public class ActivityNewsActivity extends BaseAbsActivity<PullToRefreshListView>{}
BaseActivity和BaseAbsActivity引入布局的方法一致。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.activity_simple_list, R.layout.title_default2); }initAdapter有两种方式,一种是initAdapter(),通过onGetView实现item的展示,另一种是initAdapter(adapter),即由自定义的Adapter类来实现。(注意:在之前的使用中,是直接调用BaseAbsActivity的adapter属性,不注意封装,因此在这里做了修改)
@Override public void initView() { super.initView(); refreshView = pullToRefreshAdapterViewBase.getRefreshableView(); View headView = layoutInflater.inflate(R.layout.head_activity_news, null); refreshView.addHeadView(headView); initAadapter(); }
@Override public void initView() { super.initView(); refreshView = pullToRefreshAdapterViewBase.getRefreshableView();View headView = layoutInflater.inflate(R.layout.head_activity_news, null);refreshView.addHeadView(headView); initAadapter(new ActivityNewsAdapter()); }
接着,是数据的填充。
我们在onDataPrepare中调用远程接口获取数据,通过HttpCallback调用executeOnLoadDataSuccess来填充数据。(注意indexpage和pagesize都来源于框架,也可以设置,analysis.getTotal()代表着当前展示的条目的总数)有时候可能需要重新调用数据,请使用getData(boolean isDrawDown)
@Override protected void onDataPrepare(boolean isDrawDown) { this.isDrawDown = isDrawDown; int customerId = Constants.cust.getCustomerId(); RequestApi.getInstance().getCustomerAllOrderList(customerId, getIndexPage(), getPageSize(), dataType, onLineCallBack); }
private StandardCallback onLineCallBack = new StandardCallback(this) { public void onResult(BaseAnalysis analysis) { List<OrderModel> orderModels = new ArrayList<OrderModel>(); try { JsonAnalysis<OrderModel> jsonAnalysis = new JsonAnalysis<OrderModel>(); if (!StringUtils.isEmpty(analysis.getResult())) { orderModels = jsonAnalysis.listFromJson(analysis. getStringFromResult("orderList"), OrderModel.class); } executeOnLoadDataSuccess(orderModels, analysis.getTotal(), isDrawDown); } catch (Exception e) { e.printStackTrace(); onError(StandardCallback.TYPE_RESULT_ERROR); } } @Override public void onError(int type) { pullToRefreshAdapterViewBase.onRefreshComplete(); } };
最后,是一些细节上面的处理。
在切换数据列表页面和无数据提示页面的时候,可能有的时候我们需要保留头部(headview),或者说可能有的时候无法使用上面的切换layout的显示隐藏来实现,这个时候我们可以通过BaseAbsActivity中的setFooter(view)、setFooter(int layoutId)来设置无数据提示页面,需要注意两点,一点是要在数据加载的时候切换footerview(即无法加载更多与无数据显示的切换),第二点是footerview的layout如果设置match_parent之类是无法奏效的,因为abslistview会平均分配所有子view,除非设置一个确定的高度值。
if (isDrawDown && analysis.getTotalCount() == 0){ setFooter(R.layout.empty_view_activity_news);}else{ setFooter(R.layout.footer_adapterview_none_data); setFooterViewBgColor(R.color.white);}
- BaseAbsActivity的使用
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- prefernce的使用具体使用
- 【工具使用】git 的使用
- 关于使用AsyncTaskLoader的使用
- 使用CABasicAnimation的基本使用
- 使用RocketMQ的客户端使用
- gulp的使用基本使用
- C++双缓冲技术
- LWIP使用经验---变态级(好文章)
- 如何在Linux上安裝JDK(Java Development Kit)?
- pycharm下pyuic工具使用问题解决方案
- 世界是数字的重点读书笔记(计算机科普知识)
- BaseAbsActivity的使用
- 使用BitmapShader在自定义View中画圆形
- Python--基本文件方法
- Java性能分析小工具 ---- jconsole
- 一个宏解决 iOS屏幕适配
- XMST2015下半年加班
- Android开发之利用XMPP协议实现消息的即时推送
- [Phonegap+Sencha Touch] 移动开发63 PhoneGap和Cordova的区别
- MongoDB学习5_Elasticsearch、MongoDB和Hadoop比较