Commit 777ea36c authored by chenyuling's avatar chenyuling

"修改为8个组"

parent ddc2d232
Pipeline #1716 failed with stages
package com.srthinker.statinfo.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.srthinker.statinfo.bean.Group2Bean;
import com.srthinker.statinfo.databinding.ItemDlgSelectBinding;
import java.util.ArrayList;
public class GroupSelectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context context;
private final ArrayList<Group2Bean> group2BeanList;
private int selectPos = -1; //当前选择的位置
private int tempPos = -1 ; //临时记录上次选择的位置
private OnItemClickListener onItemClickListener;
public GroupSelectAdapter(Context context, ArrayList<Group2Bean> group2BeanList){
this.context = context;
this.group2BeanList = group2BeanList;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemDlgSelectBinding binding = ItemDlgSelectBinding.inflate(LayoutInflater.from(context), parent, false);
return new ItemHolder(binding);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ItemHolder itemHolder = (ItemHolder) holder;
Group2Bean group2Bean = group2BeanList.get(position);
itemHolder.binding.tvGroupName.setSelected(holder.getLayoutPosition()==selectPos);
if (group2Bean!=null){
itemHolder.binding.tvGroupName.setText(group2Bean.getGroup_name());
itemHolder.binding.tvGroupName.setOnClickListener(v->{
itemHolder.binding.tvGroupName.setSelected(true);
//将就得位置保存下来,用于后面把旧的位置取消选择
tempPos = selectPos;
selectPos = holder.getLayoutPosition();
notifyItemChanged(tempPos);
if (onItemClickListener!=null){
onItemClickListener.onItemClick(group2Bean.getGroup_id());
}
});
}
}
@Override
public int getItemCount() {
return group2BeanList!=null&&group2BeanList.size()>0?group2BeanList.size():0;
}
private class ItemHolder extends RecyclerView.ViewHolder {
private final com.srthinker.statinfo.databinding.ItemDlgSelectBinding binding;
public ItemHolder(ItemDlgSelectBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener){
this.onItemClickListener = onItemClickListener;
}
public interface OnItemClickListener{
void onItemClick(int groupId);
}
}
package com.srthinker.statinfo.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.srthinker.statinfo.bean.Group2Bean;
import com.srthinker.statinfo.databinding.ItemGroupNewBinding;
import com.srthinker.statinfo.util.common.Utils;
import java.util.List;
public class GroupShowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context context;
private List<Group2Bean> group2BeanList;
public GroupShowAdapter(Context context, List<Group2Bean> group2BeanList){
this.context = context;
this.group2BeanList = group2BeanList;
}
public void setDataList(List<Group2Bean> group2BeanList){
this.group2BeanList = group2BeanList;
notifyDataSetChanged();
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemGroupNewBinding binding = ItemGroupNewBinding.inflate(LayoutInflater.from(context), parent, false);
return new ItemHolder(binding);
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ItemHolder itemHolder = (ItemHolder) holder;
Group2Bean group2Bean = group2BeanList.get(position);
if (position<4){ //就第一列设置宽度
// 设置item的宽度
itemHolder.mBiding.llItem.getLayoutParams().width = Utils.getScreenWidth(context)/2;
}
if (group2Bean!=null){
String text = group2Bean.getGroup_name()+":"+group2Bean.getNumber();
itemHolder.mBiding.tvGroupName.setText(text);
}
}
@Override
public int getItemCount() {
return group2BeanList!=null&&group2BeanList.size()>0?group2BeanList.size():0;
}
private class ItemHolder extends RecyclerView.ViewHolder {
private final com.srthinker.statinfo.databinding.ItemGroupNewBinding mBiding;
public ItemHolder(ItemGroupNewBinding binding) {
super(binding.getRoot());
mBiding = binding;
}
}
}
package com.srthinker.statinfo.bean;
public class Group2Bean {
private int group_id;
private String group_name;
private int number;
public Group2Bean() {
}
public Group2Bean(int group_id, String group_name) {
this.group_id = group_id;
this.group_name = group_name;
}
public Group2Bean(int group_id, String group_name, int number) {
this.group_id = group_id;
this.group_name = group_name;
this.number = number;
}
public int getGroup_id() {
return group_id;
}
public void setGroup_id(int group_id) {
this.group_id = group_id;
}
public String getGroup_name() {
return group_name;
}
public void setGroup_name(String group_name) {
this.group_name = group_name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:id="@+id/tv_group_name"
style="@style/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="autoScaleTextViewStyle"/>
<declare-styleable name="AutoScaleTextView">
<attr name="minTextSize" format="dimension"/>
</declare-styleable>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment