Android listView奇偶項採用不同的佈局
public class TimelineAdapter extends BaseAdapter {
private List<Map<String, Object>> list;
private LayoutInflater inflater;
public TimelineAdapter(List<Map<String, Object>> list) {
super();
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
View convertView_odd = null, convertView_even = null;
if(position%2 == 0){
if (convertView_even == null) {
inflater = LayoutInflater.from(parent.getContext());
convertView_even = inflater.inflate(R.layout.listview_item_even, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView_even.findViewById(R.id.title);
convertView_even.setTag(viewHolder);
}
convertView = convertView_even;
} else{
if (convertView_odd == null) {
inflater = LayoutInflater.from(parent.getContext());
convertView_odd = inflater.inflate(R.layout.listview_item_odd, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView_odd.findViewById(R.id.title);
convertView_odd.setTag(viewHolder);
}
convertView = convertView_odd;
}
String titleStr = list.get(position).get("title").toString();
viewHolder.title.setText(titleStr);
return convertView;
}
static class ViewHolder {
public TextView title;
}
}
private List<Map<String, Object>> list;
private LayoutInflater inflater;
public TimelineAdapter(List<Map<String, Object>> list) {
super();
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
View convertView_odd = null, convertView_even = null;
if(position%2 == 0){
if (convertView_even == null) {
inflater = LayoutInflater.from(parent.getContext());
convertView_even = inflater.inflate(R.layout.listview_item_even, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView_even.findViewById(R.id.title);
convertView_even.setTag(viewHolder);
}
convertView = convertView_even;
} else{
if (convertView_odd == null) {
inflater = LayoutInflater.from(parent.getContext());
convertView_odd = inflater.inflate(R.layout.listview_item_odd, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView_odd.findViewById(R.id.title);
convertView_odd.setTag(viewHolder);
}
convertView = convertView_odd;
}
String titleStr = list.get(position).get("title").toString();
viewHolder.title.setText(titleStr);
return convertView;
}
static class ViewHolder {
public TextView title;
}
}
相關文章
- ListView項(Item)的三種佈局View
- Android回顧--(十) ListView的優化和多佈局複用AndroidView優化
- React Native 小例項 採用View佈局如下檢視React NativeView
- Android ListView功能擴充套件,實現高效能的瀑布流佈局AndroidView套件
- 快應用採坑與flex佈局講解Flex
- Android 佈局Android
- Flutter 佈局(十)- ListBody、ListView、CustomMultiChildLayout詳解FlutterView
- Android中常見的佈局和佈局引數Android
- StatusLayout:顯示不同狀態的佈局
- Flex佈局-子項Flex
- Grid 佈局-子項補充及常用佈局
- Android的佈局介紹Android
- Android佈局概述Android
- Android xml 佈局AndroidXML
- CSS 列表項佈局技巧CSS
- android listview獲取選中項AndroidView
- android佈局------RelativeLayout(相對佈局)詳解Android
- android筆記二(水平佈局與垂直佈局)Android筆記
- Flutter 開發從 0 到 1(三)佈局與 ListViewFlutterView
- 寫給 Android 開發的小程式佈局指南,Flex 佈局!AndroidFlex
- Android的四個基本佈局Android
- Android中佈局的優化Android優化
- Android學習—— Android佈局Android
- Android 佈局優化Android優化
- android 介面佈局(大概)Android
- flex佈局語法+例項Flex
- Flex常見佈局例項Flex
- Flex 佈局教程:例項篇Flex
- Web 開發者如何理解 Flutter 佈局之 —— 5. ListView 和 ScrollBarWebFlutterView
- Flex佈局應用Flex
- Android上的Flexbox佈局AndroidFlex
- 深入解析Android的自定義佈局Android
- Android佈局優化技巧Android優化
- Android之TableLayout(表格佈局)Android
- android:四種基本佈局Android
- Android之佈局屬性Android
- Android GUI之View佈局AndroidGUIView
- Android響應式佈局Android