content: package com.demo.filter.typeview;
  
  import android.content.Context;
  import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.util.AttributeSet;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListView;
  
  import com.demo.filter.adapter.BaseBaseAdapter;
  import com.demo.filter.util.CommonUtil;
  
  import java.util.List;
  
  /**
   * 单选数据自定义listView
   */
  public class SingleListView<DATA> extends ListView implements AdapterView.OnItemClickListener {
  
      private BaseBaseAdapter<DATA> mAdapter;
  
  
      public SingleListView(Context context) {
          this(context, null);
      }
  
      public SingleListView(Context context, AttributeSet attrs) {
          super(context, attrs);
          init(context);
      }
  
      public SingleListView(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          init(context);
      }
  
      private void init(Context context) {
          setChoiceMode(ListView.CHOICE_MODE_SINGLE);
          setDivider(null);
          setDividerHeight(0);
          setSelector(new ColorDrawable(Color.TRANSPARENT));
  
          setOnItemClickListener(this);
      }
  
      //外部赋值调用
      public SingleListView<DATA> setSingleListAdapter(BaseBaseAdapter<DATA> adapter) {
          this.mAdapter = adapter;
          setAdapter(adapter);
          return this;
      }
  
      //接口回调
      private OnSingleListClickListener<DATA> mOnItemClickListener;
  
      public interface OnSingleListClickListener<DATA> {
          void onSingleListCallback(DATA item);
      }
  
      public SingleListView<DATA> onSingleListClick(OnSingleListClickListener<DATA> onItemClickListener) {
          this.mOnItemClickListener = onItemClickListener;
          return this;
      }
  
      //传值，并设置默认选中位置
      public void setList(List<DATA> list, int checkedPositoin) {
          mAdapter.setList(list);
  
          if (checkedPositoin != -1) {
              setItemChecked(checkedPositoin, true);
          }
      }
  
  
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
          if (CommonUtil.isFastDoubleClick()) {
              return;
          }
  
          DATA item = mAdapter.getItem(position);
          if (mOnItemClickListener != null) {
              mOnItemClickListener.onSingleListCallback(item);
          }
      }
  
  
  }
  