-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
teach
committed
Apr 28, 2020
1 parent
31efeba
commit 75e394c
Showing
13 changed files
with
284 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/donkingliang/groupedadapterdemo/activity/EmptyActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.donkingliang.groupedadapterdemo.activity; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter; | ||
import com.donkingliang.groupedadapter.holder.BaseViewHolder; | ||
import com.donkingliang.groupedadapterdemo.R; | ||
import com.donkingliang.groupedadapterdemo.adapter.EmptyAdapter; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
/** | ||
* 没有数据时,显示空布局。 | ||
*/ | ||
public class EmptyActivity extends AppCompatActivity { | ||
|
||
private TextView tvTitle; | ||
private RecyclerView rvList; | ||
private EmptyAdapter adapter; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_group_list); | ||
|
||
tvTitle = (TextView) findViewById(R.id.tv_title); | ||
rvList = (RecyclerView) findViewById(R.id.rv_list); | ||
|
||
tvTitle.setText(R.string.empty_list); | ||
|
||
rvList.setLayoutManager(new LinearLayoutManager(this)); | ||
adapter = new EmptyAdapter(this, null); | ||
// 显示空布局。默认不显示 | ||
adapter.showEmptyView(true); | ||
adapter.setOnHeaderClickListener(new GroupedRecyclerViewAdapter.OnHeaderClickListener() { | ||
@Override | ||
public void onHeaderClick(GroupedRecyclerViewAdapter groupedAdapter, BaseViewHolder holder, int groupPosition) { | ||
// 清空数据 | ||
adapter.clear(); | ||
} | ||
}); | ||
adapter.setOnChildClickListener(new GroupedRecyclerViewAdapter.OnChildClickListener() { | ||
@Override | ||
public void onChildClick(GroupedRecyclerViewAdapter groupedAdapter, BaseViewHolder holder, | ||
int groupPosition, int childPosition) { | ||
Toast.makeText(EmptyActivity.this, "子项:groupPosition = " + groupPosition | ||
+ ", childPosition = " + childPosition, | ||
Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
|
||
rvList.setAdapter(adapter); | ||
} | ||
|
||
public static void openActivity(Context context) { | ||
Intent intent = new Intent(context, EmptyActivity.class); | ||
context.startActivity(intent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/src/main/java/com/donkingliang/groupedadapterdemo/adapter/EmptyAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.donkingliang.groupedadapterdemo.adapter; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
|
||
import com.donkingliang.groupedadapter.holder.BaseViewHolder; | ||
import com.donkingliang.groupedadapterdemo.R; | ||
import com.donkingliang.groupedadapterdemo.entity.GroupEntity; | ||
import com.donkingliang.groupedadapterdemo.model.GroupModel; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* 没有数据时,显示空布局 | ||
*/ | ||
public class EmptyAdapter extends GroupedListAdapter { | ||
|
||
public EmptyAdapter(Context context, ArrayList<GroupEntity> groups) { | ||
super(context, groups); | ||
} | ||
|
||
/** | ||
* 返回false表示没有组尾 | ||
* | ||
* @param groupPosition | ||
* @return | ||
*/ | ||
@Override | ||
public boolean hasFooter(int groupPosition) { | ||
return false; | ||
} | ||
|
||
/** | ||
* 当hasFooter返回false时,这个方法不会被调用。 | ||
* | ||
* @return | ||
*/ | ||
@Override | ||
public int getFooterLayout(int viewType) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) { | ||
GroupEntity entity = mGroups.get(groupPosition); | ||
holder.setText(R.id.tv_header, entity.getHeader() + "(点击清空数据)"); | ||
} | ||
|
||
/** | ||
* 当hasFooter返回false时,这个方法不会被调用。 | ||
* | ||
* @param holder | ||
* @param groupPosition | ||
*/ | ||
@Override | ||
public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) { | ||
|
||
} | ||
|
||
@Override | ||
public View getEmptyView(ViewGroup parent) { | ||
View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_empty_view, parent, false); | ||
Button btnLoadData = view.findViewById(R.id.btn_load_data); | ||
btnLoadData.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
setData(); | ||
} | ||
}); | ||
return view; | ||
} | ||
|
||
private void setData() { | ||
setGroups(GroupModel.getGroups(10, 5)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<ImageView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/group_adapter_empty_view_image" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/empty_view" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" /> | ||
|
||
<Button | ||
android:id="@+id/btn_load_data" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/load_data" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" /> | ||
</LinearLayout> | ||
|
||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.donkingliang.groupedadapter"> | ||
|
||
<application | ||
android:label="@string/app_name"> | ||
|
||
</application> | ||
|
||
</manifest> |
Oops, something went wrong.