课前准备
- 把 BaseFragment 的其他子类在重写 initView() 方法时设置显示成功状态的 View
@Override
protected void initView() {
setUpState(State.SUCCESS);
}
课堂笔记
- 完善 fragment_error 布局 (和老师的有点出入)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/network_error_tips"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/wifi" />
<TextView
android:layout_marginTop="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_network_error_tips"
android:textSize="12sp" />
</LinearLayout>
- 在 BaseFragment 给布局设置点击事件,并添加点击重新加载的方法 onRetryClick()
@OnClick(R.id.network_error_tips)
public void retry() {
onRetryClick();
}
protected void onRetryClick() {
}
- 在子类中重写 onRetryClick() 方法,并加载数据
@Override
protected void onRetryClick() {
if (mHomePresenter != null) {
mHomePresenter.getCategories();
}
}