|
|
@@ -0,0 +1,102 @@
|
|
|
+package com.webrain.dailypay.ui.adapter.gridview;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.webrain.dailypay.R;
|
|
|
+import com.webrain.dailypay.bean.BaseInformationBean;
|
|
|
+import com.webrain.dailypay.ui.base.BaseViewHolder;
|
|
|
+import com.webrain.dailypay.utils.BaseInformationUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+
|
|
|
+public class PositionReleaseSelectAdapter extends BaseAdapter implements AdapterView.OnItemClickListener {
|
|
|
+ private Context mContext;
|
|
|
+ private List<BaseInformationBean> mData;
|
|
|
+ private List<BaseInformationBean> mSelect;
|
|
|
+
|
|
|
+ public PositionReleaseSelectAdapter(Context mContext, List<BaseInformationBean> mData) {
|
|
|
+ this.mContext = mContext;
|
|
|
+ this.mData = mData;
|
|
|
+ mSelect = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<BaseInformationBean> getSelectPosition() {
|
|
|
+ return this.mSelect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return mData == null ? 0 : mData.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseInformationBean getItem(int position) {
|
|
|
+ return mData.get(position);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getItemId(int position) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ ViewHolder holder = null;
|
|
|
+ if (convertView == null) {
|
|
|
+ holder = new ViewHolder(mContext);
|
|
|
+ convertView = holder.getView();
|
|
|
+ convertView.setTag(holder);
|
|
|
+ } else {
|
|
|
+ holder = (ViewHolder) convertView.getTag();
|
|
|
+ }
|
|
|
+ BaseInformationBean bean = getItem(position);
|
|
|
+ if (mSelect.contains(bean)) {
|
|
|
+ holder.setType(bean.getName(), true);
|
|
|
+ } else {
|
|
|
+ holder.setType(bean.getName(), false);
|
|
|
+ }
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ BaseInformationBean bean = getItem(position);
|
|
|
+ if (mSelect.contains(bean)) {
|
|
|
+ mSelect.remove(bean);
|
|
|
+ } else {
|
|
|
+ mSelect.add(bean);
|
|
|
+ }
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ class ViewHolder extends BaseViewHolder {
|
|
|
+
|
|
|
+ @BindView(R.id.tv_type)
|
|
|
+ TextView tvType;
|
|
|
+
|
|
|
+ public ViewHolder(Context mContext) {
|
|
|
+ super(mContext);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int bindViewLayoutId() {
|
|
|
+ return R.layout.item_gridview_position_release_select;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setType(String type, boolean isSelect) {
|
|
|
+ tvType.setText(type);
|
|
|
+ tvType.setSelected(isSelect);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|