Skip to content

Commit

Permalink
fix #257
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadCym committed Aug 28, 2016
1 parent 696b90e commit c40f43b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.chad.baserecyclerviewadapterhelper"
minSdkVersion 14
targetSdkVersion 23
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.chad.baserecyclerviewadapterhelper.adapter.QuickAdapter;

public class EmptyViewUseActivity extends Activity {
public class EmptyViewUseActivity extends Activity implements View.OnClickListener {
private RecyclerView mRecyclerView;
private QuickAdapter mQuickAdapter;
private boolean isNotData = true;
private View errorView;
private View notDataView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty_view_use);
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
Button btnSwuich = (Button) findViewById(R.id.btn_switch);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
initAdapter();
btnSwuich.setOnClickListener(this);
notDataView = getLayoutInflater().inflate(R.layout.empty_view, (ViewGroup) mRecyclerView.getParent(), false);
errorView = getLayoutInflater().inflate(R.layout.error_view, (ViewGroup) mRecyclerView.getParent(), false);
}

private void initAdapter() {
Expand All @@ -30,4 +38,18 @@ private void initAdapter() {
View view = getLayoutInflater().inflate(R.layout.head_view, (ViewGroup) mRecyclerView.getParent(), false);
mRecyclerView.setAdapter(mQuickAdapter);
}

@Override
public void onClick(View v) {
View view;
if (!isNotData) {
view = notDataView;
isNotData = true;
} else {
view = errorView;
isNotData = false;
}
mQuickAdapter.setEmptyView(view);
mQuickAdapter.notifyItemChanged(0);
}
}
7 changes: 6 additions & 1 deletion app/src/main/res/layout/activity_empty_view_use.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".EmptyViewUseActivity">

<Button
android:id="@+id/btn_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="switch empty view"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/layout/error_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/bg"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:layout_width="@dimen/def_height"
android:layout_height="@dimen/def_height"
android:src="@mipmap/smalllogo_gray"/>
<TextView
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/error"
android:textColor="@color/txt_color"/>
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="app_name">BaseRecyclerViewAdapterHelper</string>
<string name="title_activity_header_and_footer_use">HeaderAndFooterUseActivity</string>
<string name="no_data">There is no data</string>
<string name="error">Network error</string>
<string name="expanded">expanded</string>
<string name="collapsed">collapsed</string>
<string name="network_err">Simulation network error</string>
Expand Down

1 comment on commit c40f43b

@addappcn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

您好,还没有解决我的问题

Please sign in to comment.