网站 动态 标签页,soho没有注册公司 能建一个外贸网站吗,郑州seo优化公司排名,推广平台哪儿有怎么做想通过一个小功能的实现来表达我对编程的一些看法
一个多列表选择框#xff0c;我第一种方案用了一个自定义view逻辑全写在一个类里#xff0c;一个小时内很快就搞定了
但我也清楚#xff0c;会有很大一些人如果看这个代码#xff0c;会觉得很乱#xff0c;甚至看不懂我第一种方案用了一个自定义view逻辑全写在一个类里一个小时内很快就搞定了
但我也清楚会有很大一些人如果看这个代码会觉得很乱甚至看不懂
甚至有些人会很生气的说 这些的什么代码啊根本没法看。
我理解他们所以我特意写了一个进一步拆解成不同对象来更好理解的方式
但我想说的是如果是一个对编码有感觉的话看第一个是很容易看懂的不是他们写的不好理解而是另一些人太不懂和机器打交道了我也知道面向对象的设计但设计的粒度要多细我觉得还是的得看跟人不能一杆子打死甚至有可能委屈了那些编程高手。想象一个场景当你的领导说你的很差要你改你说好的确实必须改但你内心是一万个 ‘去你大爷的’而且无论你怎么管理自己的表情对方其实还是能感受到你的不服气他会更加极端的方式羞辱你有没有这种场景兄弟们。
是啊闲的蛋疼特意写下本人毕业不到四年就因解问题又快又好被提升管理岗一直上升到framwork层后反而进了一个一般的企业后却过得异常艰难所以人生真是充满了不确定性在此十字路口之际终于体会到那句话曾经有一份真诚的爱情放在我面前,我没有珍惜。。。
不过我觉得我完全可以傍大款的生活着躺平真就那么难吗我的hero你走吧根据个人对代码量的控制程度来选择两种编码方式
第一种方式直接在filterview里面进行点击及列表响应的处理
第二种方式专门通过一个对象FilterObject来管理选择按钮的状态和数据第一种方式
public class FilterView extends SkinCompatLinearLayout {public final static int searchType 7309;public final static String[] ChargeTitle {Speed,Brand};public final static String[] ChargeType {All,Slow,Fast};public final static String[] ChargeBrand {All,EV Station Pluz,PEA Volta,Elex by EGAT,EA Anywhere,Evolt,Sharge};//power 50 为快充public final static String[] ChargeTypeValue {0,0,50};public final static String[] ChargeBrandValue {,EV Station Pluz,PEA Volta,Elex by EGAT,EA Anywhere,Evolt,Sharge};private SkinCompatTextView[] titleViews new SkinCompatTextView[2];private final int TYPE_INDEX 0;private final int BRAND_INDEX 1;private SparseArrayString[] allColums new SparseArray();private SparseArrayString[] allColumValues new SparseArray();//每列对应的选中indexprivate SparseArrayInteger selectFilter new SparseArray();//第几列private int showRow -1;private Context mContext;private RecyclerView recyclerView;private int selectColor 0xff8ACB04;/private int normolColor 0xff35383D;public interface FilterChange{void onFilterChange(String chargetype ,String brand);}FilterChange mFilterChange;public void setFilterChange(FilterChange filterChange){mFilterChange filterChange;}public FilterView(Context context) {super(context);initdata();initView(context);}private void initdata(){allColums.put(TYPE_INDEX,ChargeType);allColums.put(BRAND_INDEX,ChargeBrand);allColumValues.put(TYPE_INDEX,ChargeTypeValue);allColumValues.put(BRAND_INDEX,ChargeBrandValue);selectFilter.put(TYPE_INDEX,0);selectFilter.put(BRAND_INDEX,0);}public FilterView(Context context, AttributeSet attrs) {super(context, attrs);initdata();initView(context);}private void initView(Context context) {mContext context;SkinCompatLinearLayout moreView (SkinCompatLinearLayout) LayoutInflater.from(mContext).inflate(R.layout.filterlayout, null);addView(moreView);moreView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));titleViews[TYPE_INDEX] moreView.findViewById(R.id.filter_left);titleViews[BRAND_INDEX] moreView.findViewById(R.id.filter_right);recyclerView moreView.findViewById(R.id.recyclerView);titleViews[TYPE_INDEX].setOnClickListener(onClickListener);titleViews[BRAND_INDEX].setOnClickListener(onClickListener);recyclerView.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));//freshListview();}OnClickListener onClickListener new OnClickListener() {Overridepublic void onClick(View v) {if(v.getId() R.id.filter_left){showRow TYPE_INDEX;}else if(v.getId() R.id.filter_right){showRow BRAND_INDEX;}freshListview();}};private void freshListview(){if (recyclerView.getVisibility() View.VISIBLE) {recyclerView.setVisibility(View.GONE);return;}recyclerView.setVisibility(View.VISIBLE);recyclerView.setAdapter(new BaseRecyclerAdapter(mContext, Arrays.asList(allColums.get(showRow)),R.layout.charge_filter_view) {Overridepublic void convert(MViewHolder holder, int position) {((TextView)holder.getView(R.id.filter_name)).setText(allColums.get(showRow)[position]);if(position selectFilter.get(showRow)){((TextView)holder.getView(R.id.filter_name)).setTextColor(selectColor);((TextView)holder.getView(R.id.filter_name)).setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.charge_select),null);}else{((TextView)holder.getView(R.id.filter_name)).setTextColor(normolColor);((TextView)holder.getView(R.id.filter_name)).setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);}}}.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {Overridepublic void onItemClick(MViewHolder holder, int position) {selectFilter.put(showRow,position);recyclerView.setVisibility(View.GONE);resetTitleview();if (mFilterChange ! null) {String brand allColumValues.get(BRAND_INDEX)[selectFilter.get(BRAND_INDEX)];String chargetype allColumValues.get(TYPE_INDEX)[selectFilter.get(TYPE_INDEX)];mFilterChange.onFilterChange(chargetype,brand);}}}));freshTitleview();}private void freshTitleview(){for(int i 0;ititleViews.length;i) {if(showRow i){titleViews[i].setTextColor(selectColor);titleViews[i].setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.charge_title_arrow_select),null);}else{titleViews[i].setTextColor(normolColor);titleViews[i].setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.icon_filterdown),null);}}}private void resetTitleview(){for(int i 0;ititleViews.length;i) {titleViews[i].setTextColor(normolColor);titleViews[i].setText(allColums.get(i)[selectFilter.get(i)]);titleViews[i].setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.icon_filterdown),null);}}}第二种通过对象来控制两个选择框的状态和数据填充
public class FilterView extends SkinCompatLinearLayout {public final static int searchType 7309;public final static String[] ChargeTitle {Speed,Brand};public final static String[] ChargeType {All,Slow,Fast};public final static String[] ChargeBrand {All,EV Station Pluz,PEA Volta,Elex by EGAT,EA Anywhere,Evolt,Sharge};//power 50 为快充public final static String[] ChargeTypeValue {0,0,50};public final static String[] ChargeBrandValue {,EV Station Pluz,PEA Volta,Elex by EGAT,EA Anywhere,Evolt,Sharge};private SkinCompatTextView[] titleViews new SkinCompatTextView[2];private final int TYPE_INDEX 0;private final int BRAND_INDEX 1;private SparseArrayString[] allColums new SparseArray();private SparseArrayString[] allColumValues new SparseArray();//第几列private int showRow -1;private Context mContext;private RecyclerView recyclerView;private int selectColor 0xff8ACB04;//R.color.download_cicle_color;private int normolColor 0xff35383D;FilterObject[] objs new FilterObject[2];public interface FilterChange{void onFilterChange(String chargetype ,String brand);}FilterChange mFilterChange;public void setFilterChange(FilterChange filterChange){mFilterChange filterChange;}public FilterView(Context context) {super(context);initdata();initView(context);}private void initdata(){allColums.put(TYPE_INDEX,ChargeType);allColums.put(BRAND_INDEX,ChargeBrand);allColumValues.put(TYPE_INDEX,ChargeTypeValue);allColumValues.put(BRAND_INDEX,ChargeBrandValue);}public FilterView(Context context, AttributeSet attrs) {super(context, attrs);initdata();initView(context);}private void initView(Context context) {mContext context;SkinCompatLinearLayout moreView (SkinCompatLinearLayout) LayoutInflater.from(mContext).inflate(R.layout.filterlayout, null);addView(moreView);moreView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));titleViews[TYPE_INDEX] moreView.findViewById(R.id.filter_left);titleViews[BRAND_INDEX] moreView.findViewById(R.id.filter_right);recyclerView moreView.findViewById(R.id.recyclerView);titleViews[TYPE_INDEX].setOnClickListener(onClickListener);titleViews[BRAND_INDEX].setOnClickListener(onClickListener);recyclerView.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));objs[BRAND_INDEX] new FilterObject(ChargeTitle[BRAND_INDEX],ChargeBrand,ChargeBrandValue,titleViews[BRAND_INDEX],0);objs[TYPE_INDEX] new FilterObject(ChargeTitle[TYPE_INDEX],ChargeType,ChargeTypeValue,titleViews[TYPE_INDEX],0);}OnClickListener onClickListener new OnClickListener() {Overridepublic void onClick(View v) {if(v.getId() R.id.filter_left){showRow TYPE_INDEX;}else if(v.getId() R.id.filter_right){showRow BRAND_INDEX;}freshListview();}};private void freshListview(){if (recyclerView.getVisibility() View.VISIBLE) {recyclerView.setVisibility(View.GONE);return;}recyclerView.setVisibility(View.VISIBLE);recyclerView.setAdapter(new BaseRecyclerAdapter(mContext, Arrays.asList(allColums.get(showRow)),R.layout.charge_filter_view) {Overridepublic void convert(MViewHolder holder, int position) {((TextView)holder.getView(R.id.filter_name)).setText(objs[showRow].getItemName(position));if(position objs[showRow].selectIndex){((TextView)holder.getView(R.id.filter_name)).setTextColor(selectColor);((TextView)holder.getView(R.id.filter_name)).setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.charge_select),null);}else{((TextView)holder.getView(R.id.filter_name)).setTextColor(normolColor);((TextView)holder.getView(R.id.filter_name)).setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);}}}.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {Overridepublic void onItemClick(MViewHolder holder, int position) {objs[showRow].setSelectIndex(position);objs[showRow].setNormorState();recyclerView.setVisibility(View.GONE);if (mFilterChange ! null) {mFilterChange.onFilterChange(objs[TYPE_INDEX].getSelectValue(),objs[BRAND_INDEX].getSelectValue());}}}));objs[showRow].setSelectState();}// todo use obj insteadclass FilterObject {public FilterObject(String title,String[] listShows,String[] listValues,SkinCompatTextView titleView,int selectIndex){this.title title;this.listShows listShows;this.listValues listValues;this.titleView titleView;}public String title ;public String[] listShows ;public String[] listValues;public SkinCompatTextView titleView ;public void setSelectIndex(int selectIndex) {this.selectIndex selectIndex;}public String getSelectValue(){return listValues[selectIndex];}public String getItemName(int index){return listShows[index];}//第几列public int selectIndex 0;public void setNormorState(){titleView.setTextColor(normolColor);titleView.setText(listShows[selectIndex]);titleView.setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.icon_filterdown),null);}public void setSelectState(){titleView.setTextColor(selectColor);titleView.setText(listShows[selectIndex]);titleView.setCompoundDrawablesWithIntrinsicBounds(null,null,ContextCompat.getDrawable(ContextHelper.getContext(), R.drawable.charge_title_arrow_select),null);}}}