1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| import android.app.Activity; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemClickListener; import com.hhkj.mcb.R; import com.hhkj.mcb.common.ui.bean.CarBean; import com.hhkj.mcb.seller.callbuy.adapter.TruckAdapter;
import java.util.List;
import butterknife.BindView; import butterknife.ButterKnife;
public class TruckPop extends BasePopupWindow { @BindView(R.id.rv_truck) RecyclerView rvTruck;
private final View view; private Activity activity; private List<CarBean> carBeanList; private TruckAdapter truckAdapter; private OnSelectedListener onSelectedListener; private int selectIndex = 0;
public TruckPop(Activity activity, int height, List<CarBean> carBeanList) { this(activity,height,carBeanList,0); }
public TruckPop(Activity activity, int height, List<CarBean> carBeanList, int selectIndex) { super(activity); this.activity = activity; this.carBeanList = carBeanList; this.selectIndex = selectIndex;
setOutsideTouchable(true); setFocusable(true); setWidth(ViewGroup.LayoutParams.MATCH_PARENT); setHeight(height); setBackgroundDrawable(new ColorDrawable(0x30000000)); view = LayoutInflater.from(activity).inflate(R.layout.pop_truck, null); setContentView(view); ButterKnife.bind(this, view); initView(); }
private void initView() { view.setOnClickListener(view -> { dismiss(); });
rvTruck.setLayoutManager(new LinearLayoutManager(activity)); rvTruck.setAdapter(truckAdapter = new TruckAdapter(R.layout.truck_item,selectIndex)); View headerView = LayoutInflater.from(activity).inflate(R.layout.truck_item, null); TextView header = headerView.findViewById(R.id.tv_carNumber); headerView.setBackgroundColor(Color.WHITE); header.setText("全部"); header.setTextColor(Color.parseColor("#31C863")); truckAdapter.addHeaderView(headerView); truckAdapter.setList(carBeanList); truckAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) { CarBean carBean = (CarBean) adapter.getData().get(position); truckAdapter.setSelectIndex(position); if (onSelectedListener != null) { onSelectedListener.onSelect(carBean, position); } } });
}
public interface OnSelectedListener { void onSelect(CarBean carBean, int position); }
public OnSelectedListener getOnSelectedListener() { return onSelectedListener; }
public void setOnSelectedListener(OnSelectedListener onSelectedListener) { this.onSelectedListener = onSelectedListener; } }
|