自定义Android知识Android开发

打造一个傻瓜式的处理下拉刷新,滚动底部自动加载更多,分页加载,自

2016-10-18  本文已影响982人  峥嵘岁月Z

扯谈:

正文:

效果图:

代码:

/**
 * 意见反馈列表
 */
public class FeedbackListActivity extends TitleBarActivity implements SwipeRefreshLayout.OnRefreshListener {
    @Bind(R.id.recycler_view) XRecyclerView mRecyclerView;
    @Bind(R.id.content_view) SwipeRefreshLayout mContentView;
    @Bind(R.id.multiple_status_view) MultipleStatusView mMultipleStatusView;
    private FeedbackPresenter mPresenter;
    FeedbackAdapter mAdapter;
    LoadPageListDataView<FeedbackModel> mListDataView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback_list);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        ViewUtils.initVerticalLinearRecyclerView(this, mRecyclerView);
        setSwipeRefreshLayout(mContentView);
        mAdapter = new FeedbackAdapter(mRecyclerView, R.layout.item_feed_back);
        mPresenter = new FeedbackPresenter();
        mListDataView = new LoadPageListDataView<FeedbackModel>(this, mMultipleStatusView, mContentView, mRecyclerView, mAdapter);
        mPresenter.onTakeView(mListDataView);
        mPresenter.onCreate();
        mRecyclerView.setAdapter(mAdapter);
        mContentView.setOnRefreshListener(this);
        mMultipleStatusView.setOnRetryClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mPresenter != null) mPresenter.downPullRefreshList();
            }
        });
    }

    @Override
    public void onRefresh() {
        if (mPresenter != null) mPresenter.downPullRefreshList();
    }

    @Override
    public void onCreateCustomTitleBar(TitleBar titleBar) {
        setTitle(R.string.title_activity_feedback_list);
        setBackBtn();
        titleBar.setActionTextColor(Color.WHITE);
        titleBar.addAction(new TitleBar.TextAction(getString(R.string.add_feed_back)) {
            @Override
            public void performAction(View view) {
                IntentUtils.showActivity(FeedbackListActivity.this, AddFeedbackActivity.class);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mPresenter!=null) mPresenter.destroy();
        ButterKnife.unbind(this);
    }
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<com.mk.common.widget.emptyload.MultipleStatusView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/multiple_status_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/content_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <com.mk.common.widget.xrecyclerview.XRecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </android.support.v4.widget.SwipeRefreshLayout>

</com.mk.common.widget.emptyload.MultipleStatusView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:paddingLeft="@dimen/margin_10"
              android:paddingRight="@dimen/margin_10"
              android:paddingTop="@dimen/margin_10">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape_gray_stroke"
        android:minHeight="@dimen/margin_100"
        android:orientation="vertical"
        >
        <TextView
            android:id="@+id/tv_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_5"
            android:textColor="@android:color/black"
            tools:text="时间"
            />
        <View style="@style/HLine"/>
        <TextView
            android:id="@+id/tv_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="@dimen/margin_5"
            android:text="意见反馈内容"
            />
    </LinearLayout>
</LinearLayout>

总结

上一篇 下一篇

猜你喜欢

热点阅读