设置标签
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.shayu.onetoone.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.bean.LabelBean;
|
||||
import com.xuexiang.xui.widget.flowlayout.BaseTagAdapter;
|
||||
|
||||
public class LabelChooseTagAdapter extends BaseTagAdapter<LabelBean.Children, TextView> {
|
||||
|
||||
OnSureOnClickListener onSureOnClickListener;
|
||||
|
||||
Context mContext;
|
||||
|
||||
public LabelChooseTagAdapter(Context context, OnSureOnClickListener onSureOnClickListener) {
|
||||
super(context);
|
||||
this.onSureOnClickListener = onSureOnClickListener;
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public LabelChooseTagAdapter(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextView newViewHolder(View convertView) {
|
||||
return (TextView) convertView.findViewById(R.id.tv_tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.adapter_item_tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(TextView textView, LabelBean.Children item, int position) {
|
||||
textView.setText(item.getCn_title());
|
||||
if (item.isSelect()) {
|
||||
textView.setBackground(getDrawable(R.drawable.bg_rect_round_tag_btn1));
|
||||
textView.setTextColor(mContext.getResources().getColor(R.color.white));
|
||||
} else {
|
||||
textView.setBackground(getDrawable(R.drawable.bg_rect_round_tag_btn));
|
||||
textView.setTextColor(mContext.getResources().getColor(R.color.black2));
|
||||
}
|
||||
textView.setOnClickListener(v -> {
|
||||
item.setSelect(!item.isSelect());
|
||||
onSureOnClickListener.sure(item);
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
|
||||
public interface OnSureOnClickListener {
|
||||
void sure(LabelBean.Children labelBean);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.shayu.onetoone.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.bean.LabelBean;
|
||||
import com.xuexiang.xui.widget.flowlayout.BaseTagAdapter;
|
||||
|
||||
public class LabelTagAdapter extends BaseTagAdapter<LabelBean.Children, TextView> {
|
||||
|
||||
OnSureOnClickListener onSureOnClickListener;
|
||||
|
||||
Context mContext;
|
||||
|
||||
public LabelTagAdapter(Context context, OnSureOnClickListener onSureOnClickListener) {
|
||||
super(context);
|
||||
this.onSureOnClickListener = onSureOnClickListener;
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public LabelTagAdapter(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextView newViewHolder(View convertView) {
|
||||
return (TextView) convertView.findViewById(R.id.tv_tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.adapter_item_tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(TextView textView, LabelBean.Children item, int position) {
|
||||
textView.setText(item.getCn_title());
|
||||
textView.setBackground(getDrawable(R.drawable.bg_rect_round_tag_btn));
|
||||
textView.setTextColor(mContext.getResources().getColor(R.color.black2));
|
||||
}
|
||||
|
||||
public interface OnSureOnClickListener {
|
||||
void sure(LabelBean.Children labelBean);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.shayu.onetoone.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.bean.LabelBean;
|
||||
import com.xuexiang.xui.widget.flowlayout.FlowTagLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LableChooseAdapter extends RecyclerView.Adapter<LableChooseAdapter.ViewHolder> {
|
||||
private Context mContext;
|
||||
private List<LabelBean> list;
|
||||
private int selectPosition = 0;
|
||||
|
||||
public onItemLabelClicklistener onItemLabelClicklistener;
|
||||
|
||||
public LableChooseAdapter(Context mContext, onItemLabelClicklistener onItemLabelClicklistener) {
|
||||
this.mContext = mContext;
|
||||
list = new ArrayList<>();
|
||||
this.onItemLabelClicklistener = onItemLabelClicklistener;
|
||||
}
|
||||
|
||||
public void setList(List<LabelBean> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_choose_label, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
holder.setData(list.get(position), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public LabelBean getItem() {
|
||||
return list.get(selectPosition);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private FlowTagLayout flowTagLayout;
|
||||
private TextView title;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
flowTagLayout = itemView.findViewById(R.id.myFlowTag);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
}
|
||||
|
||||
private void setData(LabelBean labelBean, int position) {
|
||||
LabelChooseTagAdapter tagAdapter1 = new LabelChooseTagAdapter(mContext, new LabelChooseTagAdapter.OnSureOnClickListener() {
|
||||
@Override
|
||||
public void sure(LabelBean.Children labelBean) {
|
||||
if (onItemLabelClicklistener != null) {
|
||||
onItemLabelClicklistener.onChoose(labelBean);
|
||||
}
|
||||
}
|
||||
});
|
||||
flowTagLayout.setAdapter(tagAdapter1);
|
||||
flowTagLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_NONE);
|
||||
tagAdapter1.setData(labelBean.getChildren());
|
||||
title.setText(labelBean.getCn_title());
|
||||
title.setTag(labelBean);
|
||||
}
|
||||
}
|
||||
|
||||
public interface onItemLabelClicklistener {
|
||||
void onChoose(LabelBean.Children children);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user