package safeluck.drive.evaluation.adapter;
|
|
import android.content.Context;
|
import android.util.Log;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.Button;
|
import android.widget.TextView;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import safeluck.drive.evaluation.R;
|
import safeluck.drive.evaluation.bean.BaseDataUIBean;
|
import safeluck.drive.evaluation.fragment.BaseDatasFragment;
|
|
/**
|
* MyApplication2
|
* Created by lzw on 2020/1/10. 16:33:13
|
* 邮箱:632393724@qq.com
|
* All Rights Saved! Chongqing AnYun Tech co. LTD
|
*/
|
|
public class BaseDataInfoAdapter extends BaseAdapter implements View.OnClickListener {
|
private List<BaseDataUIBean> persons = new ArrayList<>();
|
private final static String TAG = "anyun_info";
|
private Context mContext;
|
private Callback mCallback;
|
@Override
|
public int getCount() {
|
return persons.size();
|
}
|
|
@Override
|
public BaseDataUIBean getItem(int i) {
|
return persons.get(i);
|
}
|
|
@Override
|
public int getViewTypeCount() {
|
return 2;
|
}
|
|
@Override
|
public long getItemId(int i) {
|
return i;
|
}
|
|
@Override
|
public int getItemViewType(int position) {
|
if (persons.get(position).getType()==0){
|
return 0;
|
}else{
|
|
return 1;
|
}
|
}
|
|
@Override
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
InfoHodler infoHodler = null;
|
MapCarInfoHodler mapCarinfoHodler = null;
|
|
switch (getItemViewType(i)){
|
case 0:
|
if (view == null){
|
view = LayoutInflater.from(mContext).inflate(R.layout.gps_info_item,null);
|
infoHodler = new InfoHodler();
|
infoHodler.name = view.findViewById(R.id.text_check_info);
|
view.setTag(infoHodler);
|
}else{
|
infoHodler = (InfoHodler) view.getTag();
|
}
|
infoHodler.name.setText(getItem(i).getDes());
|
infoHodler.name.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().
|
getDrawable(getItem(i).getRes_id()),null,null,null);
|
infoHodler.name.setCompoundDrawablePadding(10);
|
break;
|
default:
|
Log.i(TAG,"Defalut");
|
if (view == null){
|
view = LayoutInflater.from(mContext).inflate(R.layout.map_car_info_update,null);
|
mapCarinfoHodler = new MapCarInfoHodler();
|
mapCarinfoHodler.name = view.findViewById(R.id.tv_map_name);
|
mapCarinfoHodler.version = view.findViewById(R.id.tv_version);
|
mapCarinfoHodler.btn = view.findViewById(R.id.btn_update_map_car);
|
view.setTag(mapCarinfoHodler);
|
}else{
|
mapCarinfoHodler = (MapCarInfoHodler) view.getTag();
|
}
|
mapCarinfoHodler.btn.setOnClickListener(this);
|
mapCarinfoHodler.btn.setTag(i);
|
mapCarinfoHodler.name.setText(getItem(i).getDes());
|
mapCarinfoHodler.name.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().
|
getDrawable(getItem(i).getRes_id()),null,null,null);
|
mapCarinfoHodler.name.setCompoundDrawablePadding(10);
|
|
mapCarinfoHodler.btn.setText(getItem(i).getBtn_txt());
|
mapCarinfoHodler.version.setText(getItem(i).getVersion());
|
|
|
break;
|
}
|
|
|
|
return view;
|
}
|
|
public BaseDataInfoAdapter(Context mContext) {
|
this.mContext = mContext;
|
}
|
/**
|
* //先清掉原来的所有数据再添加新加进来所有的数据
|
* @param ps
|
*/
|
public void addAll(List<BaseDataUIBean> ps){
|
persons.clear();//先清掉原来的所有数据
|
persons.addAll(ps);//再添加新加进来所有的数据
|
notifyDataSetChanged();//刷新界面
|
}
|
|
@Override
|
public void onClick(View v) {
|
if (mCallback != null){
|
mCallback.click(v);
|
}
|
}
|
|
public void setCallback(Callback call) {
|
this.mCallback = call;
|
}
|
|
/**
|
* 自定义接口,用于回调按钮点击事件到Fragment、Activity
|
*/
|
public interface Callback{
|
void click(View view);
|
}
|
|
static class InfoHodler {
|
|
|
public TextView name;//姓名
|
|
|
|
|
|
}
|
static class MapCarInfoHodler {
|
|
|
public TextView name;//姓名
|
public TextView version;//姓名
|
public Button btn;
|
|
|
|
|
}
|
|
}
|