-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7065e0
commit 3f02e12
Showing
5 changed files
with
270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package aweme.ui.adapter; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.RelativeLayout; | ||
import android.widget.RelativeLayout.LayoutParams; | ||
import android.widget.TextView; | ||
|
||
import aweme.ui.base.BaseListAdapter; | ||
import data.Info; | ||
|
||
/** | ||
* Created by Administrator on 2018/7/22. | ||
*/ | ||
@SuppressWarnings("ResourceType") | ||
public class InfoAdapter extends BaseListAdapter<Info>{ | ||
|
||
public InfoAdapter(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) { | ||
RelativeLayout layout = new RelativeLayout(getContext()); | ||
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); | ||
|
||
TextView title = new TextView(getContext()); | ||
LayoutParams title_params = new LayoutParams(LayoutParams.WRAP_CONTENT, dp2px(40)); | ||
title_params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); | ||
title_params.setMargins(dp2px(10), 0, 0, 0); | ||
title.setLayoutParams(title_params); | ||
|
||
TextView subTitle = new TextView(getContext()); | ||
LayoutParams subTitle_params = new LayoutParams(LayoutParams.WRAP_CONTENT, dp2px(40)); | ||
subTitle_params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); | ||
subTitle_params.setMargins(0, 0, 0, dp2px(10)); | ||
subTitle.setLayoutParams(subTitle_params); | ||
|
||
layout.addView(title); | ||
layout.addView(subTitle); | ||
return layout; | ||
} | ||
|
||
@Override | ||
public ViewHolder<Info> onCreateViewHolder(View view, int viewType) { | ||
return new InfoHolder(view, this); | ||
} | ||
|
||
public final class InfoHolder extends ViewHolder<Info>{ | ||
|
||
public InfoHolder(View view, BaseListAdapter<Info> baseListAdapter) { | ||
super(view, baseListAdapter); | ||
} | ||
|
||
@Override | ||
public void onBind(int position, int viewType) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package aweme.ui.base; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by Administrator on 2018/7/22. | ||
*/ | ||
|
||
public abstract class BaseListAdapter<T> extends BaseAdapter{ | ||
private Context mContext; | ||
private List<T> mItems; | ||
private LayoutInflater mLayoutInflater; | ||
|
||
public BaseListAdapter(Context context) { | ||
mContext = context; | ||
mLayoutInflater = LayoutInflater.from(context); | ||
} | ||
|
||
public List<T> getmItems(){ | ||
return mItems; | ||
} | ||
|
||
public Context getContext(){ | ||
return mContext; | ||
} | ||
|
||
public void setItems(List<T> items){ | ||
mItems = items; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mItems == null ? 0 : mItems.size(); | ||
} | ||
|
||
@Override | ||
public T getItem(int position) { | ||
return mItems == null ? null : mItems.get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
|
||
int viewType = getItemViewType(position); | ||
|
||
if (convertView == null){ | ||
|
||
//创建View | ||
convertView = onCreateView(mLayoutInflater, parent, viewType); | ||
|
||
//创建ViewHolder | ||
ViewHolder<T> viewHolder = onCreateViewHolder(convertView, viewType); | ||
|
||
//初始化操作 | ||
if (viewHolder != null) viewHolder.onInitialize(); | ||
|
||
//保存 | ||
convertView.setTag(viewHolder); | ||
} | ||
|
||
ViewHolder<T> viewHolder = (ViewHolder<T>) convertView.getTag(); | ||
|
||
if (viewHolder != null){ | ||
//进行绑定 | ||
viewHolder.mPosition = position; | ||
viewHolder.onBind(position,viewType); | ||
} | ||
|
||
return convertView; | ||
} | ||
|
||
/** | ||
* 实例显示的View | ||
* @param layoutInflater | ||
* @param parent | ||
* @param viewType | ||
* @return | ||
*/ | ||
public abstract View onCreateView(LayoutInflater layoutInflater, ViewGroup parent, int viewType); | ||
|
||
/** | ||
* 初始化View | ||
* @param view | ||
* @param viewType | ||
* @return | ||
*/ | ||
public abstract ViewHolder<T> onCreateViewHolder(View view, int viewType); | ||
|
||
public abstract class ViewHolder<T>{ | ||
|
||
protected int mPosition; | ||
protected View mItemView; | ||
private BaseListAdapter<T> mBaseListAdapter; | ||
|
||
public ViewHolder(View view, BaseListAdapter<T> baseListAdapter) { | ||
this.mItemView = view; | ||
this.mBaseListAdapter = baseListAdapter; | ||
} | ||
|
||
public void onInitialize(){ | ||
|
||
} | ||
|
||
public View getItemView(){ | ||
return mItemView; | ||
} | ||
|
||
/** | ||
* 绑定View, 用于数据跟View进行绑定 | ||
* @param position | ||
* @param viewType | ||
*/ | ||
public abstract void onBind(int position, int viewType); | ||
|
||
/** | ||
* 获取指定索引id的内容信息 | ||
* @param position 索引id | ||
* @return 指定id的内容信息 | ||
*/ | ||
public T getItem(int position){ | ||
return mBaseListAdapter.getItem(position); | ||
} | ||
|
||
/** | ||
* 获取适配器中数据下标 | ||
* @return | ||
*/ | ||
public int getAdapterPosition() { | ||
return mPosition; | ||
} | ||
} | ||
|
||
protected int dp2px(float dp){ | ||
final float scale = getContext().getResources().getDisplayMetrics().density; | ||
return (int) (dp * scale + 0.5f); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package data; | ||
|
||
/** | ||
* Created by Administrator on 2018/7/22. | ||
*/ | ||
|
||
public class Info { | ||
|
||
//normal 0 | ||
//with subTitle 1 | ||
//update info 2 | ||
|
||
int type; | ||
String title; | ||
String subTitle; | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public String getSubTitle() { | ||
return subTitle; | ||
} | ||
|
||
public void setType(int type) { | ||
this.type = type; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public void setSubTitle(String subTitle) { | ||
this.subTitle = subTitle; | ||
} | ||
} |