增加了没有更多数据的底部View
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package com.mogo.module.v2x.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import com.mogo.module.common.entity.V2XHistoryScenarioData;
|
||||
import com.mogo.module.common.entity.V2XMessageEntity;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.adapter.holder.V2XScenarioHistoryIllegalParkVH;
|
||||
import com.mogo.module.v2x.adapter.holder.V2XScenarioHistoryOtherSeekHelpVH;
|
||||
import com.mogo.module.v2x.adapter.holder.V2XScenarioHistoryRoadEventVH;
|
||||
@@ -16,7 +20,7 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* @author donghongyu
|
||||
*/
|
||||
public class V2XScenarioHistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public class V2XScenarioHistoryAdapter extends RecyclerView.Adapter<ViewHolder> {
|
||||
|
||||
private ArrayList<V2XHistoryScenarioData> mV2XHistoryScenarioData;
|
||||
|
||||
@@ -28,8 +32,8 @@ public class V2XScenarioHistoryAdapter extends RecyclerView.Adapter<RecyclerView
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
RecyclerView.ViewHolder holder;
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ViewHolder holder;
|
||||
switch (viewType) {
|
||||
//道路事件详情
|
||||
case V2XMessageEntity.V2XTypeEnum.ALERT_ROAD_WARNING:
|
||||
@@ -43,35 +47,57 @@ public class V2XScenarioHistoryAdapter extends RecyclerView.Adapter<RecyclerView
|
||||
case V2XMessageEntity.V2XTypeEnum.ALERT_SEEK_WARNING:
|
||||
holder = new V2XScenarioHistoryOtherSeekHelpVH(parent);
|
||||
break;
|
||||
//没有更多的数据的Footer
|
||||
default:
|
||||
holder = new V2XScenarioHistoryRoadEventVH(parent);
|
||||
View footerView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.footer_nomore_view, parent, false);
|
||||
holder = new FooterViewHolder(footerView);
|
||||
break;
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof V2XScenarioHistoryRoadEventVH) {
|
||||
((V2XScenarioHistoryRoadEventVH) holder).initView(mV2XHistoryScenarioData.get(position));
|
||||
}
|
||||
if (holder instanceof V2XScenarioHistoryIllegalParkVH) {
|
||||
((V2XScenarioHistoryIllegalParkVH) holder).initView(mV2XHistoryScenarioData.get(position));
|
||||
}
|
||||
if (holder instanceof V2XScenarioHistoryOtherSeekHelpVH) {
|
||||
((V2XScenarioHistoryOtherSeekHelpVH) holder).initView(mV2XHistoryScenarioData.get(position));
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
if (position < mV2XHistoryScenarioData.size()) {
|
||||
if (holder instanceof V2XScenarioHistoryRoadEventVH) {
|
||||
((V2XScenarioHistoryRoadEventVH) holder).initView(mV2XHistoryScenarioData.get(position));
|
||||
}
|
||||
if (holder instanceof V2XScenarioHistoryIllegalParkVH) {
|
||||
((V2XScenarioHistoryIllegalParkVH) holder).initView(mV2XHistoryScenarioData.get(position));
|
||||
}
|
||||
if (holder instanceof V2XScenarioHistoryOtherSeekHelpVH) {
|
||||
((V2XScenarioHistoryOtherSeekHelpVH) holder).initView(mV2XHistoryScenarioData.get(position));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return mV2XHistoryScenarioData.get(position).getScenarioType();
|
||||
if (position < mV2XHistoryScenarioData.size()) {
|
||||
return mV2XHistoryScenarioData.get(position).getScenarioType();
|
||||
} else {
|
||||
// 没有更多的Footer
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mV2XHistoryScenarioData == null ? 0 : mV2XHistoryScenarioData.size();
|
||||
// 多添加一个Footer
|
||||
return mV2XHistoryScenarioData == null ? 0 : mV2XHistoryScenarioData.size() + 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Footer 视图
|
||||
*/
|
||||
static class FooterViewHolder extends RecyclerView.ViewHolder {
|
||||
public FooterViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_102"
|
||||
android:layout_marginEnd="@dimen/dp_102"
|
||||
android:paddingTop="@dimen/dp_56"
|
||||
android:paddingBottom="@dimen/dp_56">
|
||||
|
||||
<View
|
||||
android:id="@+id/viewLinStart"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1px"
|
||||
android:background="#979797"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvNoMoreDataTrip"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvNoMoreDataTrip"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvNoMoreDataTrip" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvNoMoreDataTrip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_32"
|
||||
android:layout_marginEnd="@dimen/dp_32"
|
||||
android:text="没有更多记录了"
|
||||
android:textColor="#99FFFFFF"
|
||||
android:textSize="@dimen/dp_26"
|
||||
app:layout_constraintEnd_toStartOf="@+id/viewLinEnd"
|
||||
app:layout_constraintStart_toEndOf="@+id/viewLinStart"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<View
|
||||
android:id="@+id/viewLinEnd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1px"
|
||||
android:background="#979797"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvNoMoreDataTrip"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/tvNoMoreDataTrip"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvNoMoreDataTrip" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user