Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfusheng committed Nov 27, 2016
1 parent ca7e477 commit c1fb129
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public BaseListAdapter(Context context) {
public BaseListAdapter(Context context, List<E> list) {
this(context);
mList = list;
mInflater = LayoutInflater.from(context);
mImageManager = new ImageManager(context);
}

@Override
Expand All @@ -42,11 +40,9 @@ public List<E> getData() {
return mList;
}

public void addALL(List<E> lists){
if(lists==null||lists.size()==0){
return ;
}
mList.addAll(lists);
public void addALL(List<E> list){
if(list==null||list.size()==0) return;
mList.addAll(list);
}
public void add(E item){
mList.add(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sunfusheng.StickyHeaderListView.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
Expand All @@ -20,8 +19,6 @@
*/
public class FilterLeftAdapter extends BaseListAdapter<FilterTwoEntity> {

private FilterTwoEntity selectedEntity;

public FilterLeftAdapter(Context context) {
super(context);
}
Expand All @@ -31,9 +28,8 @@ public FilterLeftAdapter(Context context, List<FilterTwoEntity> list) {
}

public void setSelectedEntity(FilterTwoEntity filterEntity) {
this.selectedEntity = filterEntity;
for (FilterTwoEntity entity : getData()) {
entity.setSelected(entity.getType().equals(selectedEntity.getType()));
entity.setSelected(filterEntity != null && entity.getType().equals(filterEntity.getType()));
}
notifyDataSetChanged();
}
Expand All @@ -42,7 +38,7 @@ public void setSelectedEntity(FilterTwoEntity filterEntity) {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_filter_left, null);
convertView = mInflater.inflate(R.layout.item_filter_left, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sunfusheng.StickyHeaderListView.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -20,8 +19,6 @@
*/
public class FilterOneAdapter extends BaseListAdapter<FilterEntity> {

private FilterEntity selectedEntity;

public FilterOneAdapter(Context context) {
super(context);
}
Expand All @@ -31,9 +28,8 @@ public FilterOneAdapter(Context context, List<FilterEntity> list) {
}

public void setSelectedEntity(FilterEntity filterEntity) {
this.selectedEntity = filterEntity;
for (FilterEntity entity : getData()) {
entity.setSelected(entity.getKey().equals(selectedEntity.getKey()));
entity.setSelected(filterEntity != null && entity.getKey().equals(filterEntity.getKey()));
}
notifyDataSetChanged();
}
Expand All @@ -42,7 +38,7 @@ public void setSelectedEntity(FilterEntity filterEntity) {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_filter_one, null);
convertView = mInflater.inflate(R.layout.item_filter_one, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sunfusheng.StickyHeaderListView.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand Down Expand Up @@ -35,7 +34,7 @@ public void setSelectedEntity(FilterEntity filterEntity) {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_filter_one, null);
convertView = mInflater.inflate(R.layout.item_filter_one, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -29,7 +28,7 @@ public HeaderChannelAdapter(Context context, List<ChannelEntity> list) {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_channel, null);
convertView = mInflater.inflate(R.layout.item_channel, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand Down Expand Up @@ -33,7 +32,7 @@ public HeaderOperationAdapter(Context context, List<OperationEntity> list) {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_operation, null);
convertView = mInflater.inflate(R.layout.item_operation, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
Expand Down

0 comments on commit c1fb129

Please sign in to comment.