| | |
| | | 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 safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.bean.BaseDataUIBean; |
| | | import safeluck.drive.evaluation.fragment.BaseDatasFragment; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | |
| | | public class BaseDataInfoAdapter extends BaseAdapter { |
| | | private List<BaseDataUIBean> persons = new ArrayList<>();//gps信息 |
| | | 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 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; |
| | | 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(); |
| | | 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; |
| | | } |
| | | |
| | | infoHodler.name.setText(getItem(i).getDes()); |
| | | infoHodler.name.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources(). |
| | | getDrawable(getItem(i).getRes_id()),null,null,null); |
| | | infoHodler.name.setCompoundDrawablePadding(10); |
| | | |
| | | |
| | | return view; |
| | | } |
| | | |
| | |
| | | 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 { |
| | | |
| | | |
| | |
| | | |
| | | |
| | | } |
| | | static class MapCarInfoHodler { |
| | | |
| | | |
| | | public TextView name;//姓名 |
| | | public TextView version;//姓名 |
| | | public Button btn; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |