android listview多视图嵌套多视图
笔记,listview视图总结
public class HomeEduMoreAdapter extends BaseAdapter { private final String TAG = "HomeEduMoreAdapter"; private static final int TYPE_COMMON = 0;
private static final int TYPE_BL = 1;
private static final int TYPE_NONE = 2;
private static final int TYPE_THREE = 3;
private static final int TYPE_QUESTION = 4;
private int TYPE_COUNT = 5; private LayoutInflater inflater;
private List<HomeEdus> list;
private Context context;
private DisplayImageOptions options;
private ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener(); public HomeEduMoreAdapter(Context context, List<HomeEdus> objects) {
this.context = context;
// groupUserDao = new GroupUserDao(context);
inflater = LayoutInflater.from(context);
list = objects;
options = new DisplayImageOptions.Builder().cacheInMemory(true)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Bitmap.Config.RGB_565).cacheOnDisk(true)
.showImageOnLoading(R.drawable.icon_default)// 设置图片在下载期间显示的图片
.showImageForEmptyUri(R.drawable.icon_default)// 设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.icon_default)// 设置图片加载/解码过程中错误时候显示的图片
.considerExifParams(true).build();
} @Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
} @Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return TYPE_COUNT;
} @Override
public HomeEdus getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
} @Override
public long getItemId(int postion) {
// TODO Auto-generated method stub
return postion;
} @Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
HomeEdus edus = getItem(position); String type = edus.getType();// 菜单类型
int result = TYPE_COMMON;
switch (type) {
case "hx":
result = TYPE_COMMON;
break;
case "wd":
if (edus.getPic1() == null || edus.getPic1().equals("")) {
result = TYPE_QUESTION;
}else {
result = TYPE_COMMON;
} break;
case "jt":
result = TYPE_COMMON;
break;
case "bl":
result = TYPE_BL;
break;
default:
String jx = edus.getType();// 精选内容类型
switch (jx) {
default:
Integer imgNum = Integer.parseInt(edus.getImgNum());
if (imgNum != null && imgNum > 0 && imgNum < 3) {
result = TYPE_COMMON;
} else if (imgNum != null && imgNum >= 3) {
result = TYPE_THREE;
} else {
result = TYPE_NONE;
} break;
} break;
}
return result;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final HomeEdus model = getItem(position);
int type = getItemViewType(position);
final ViewHolder holder; if (convertView == null) {
holder = new ViewHolder();
WindowManager manager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
int width = manager.getDefaultDisplay().getWidth();
int height = manager.getDefaultDisplay().getWidth() / 2;
switch (type) {
case TYPE_COMMON:
convertView = inflater.inflate(R.layout.item_home_edus, null);
holder.tv_content = (QSTextView) convertView
.findViewById(R.id.tv_content);
holder.tv_content.setTextColor(Color.GRAY);
holder.tv_title = (QSTextView) convertView
.findViewById(R.id.tv_title);
holder.tv_name = (TextView) convertView
.findViewById(R.id.tv_name);
// holder.img_head = (CircleImageView) convertView
// .findViewById(R.id.img_head);
holder.img_content = (ImageView) convertView
.findViewById(R.id.img_content);
holder.tv_read = (TextView) convertView
.findViewById(R.id.tv_read);
holder.tv_comment = (TextView) convertView
.findViewById(R.id.tv_comment);
holder.tv_thumbupNum = (TextView) convertView
.findViewById(R.id.tv_thumbupNum);
break;
case TYPE_QUESTION:
convertView = inflater.inflate(R.layout.item_home_question, null);
holder.tv_content = (QSTextView) convertView
.findViewById(R.id.tv_content);
holder.tv_content.setTextColor(Color.GRAY);
holder.tv_title = (QSTextView) convertView
.findViewById(R.id.tv_title);
holder.tv_name = (TextView) convertView
.findViewById(R.id.tv_name);
holder.tv_read = (TextView) convertView
.findViewById(R.id.tv_read);
holder.tv_comment = (TextView) convertView
.findViewById(R.id.tv_comment);
holder.tv_thumbupNum = (TextView) convertView
.findViewById(R.id.tv_thumbupNum);
break;
case TYPE_BL:
case TYPE_NONE:
convertView = inflater.inflate(R.layout.item_home_case, null);
holder.tv_content = (QSTextView) convertView
.findViewById(R.id.tv_content);
holder.tv_content.setTextColor(Color.GRAY);
holder.tv_title = (QSTextView) convertView
.findViewById(R.id.tv_title);
holder.tv_name = (TextView) convertView
.findViewById(R.id.tv_name);
holder.img_content = (ImageView) convertView
.findViewById(R.id.img_content); LayoutParams para1 = holder.img_content.getLayoutParams();
para1.height = height;
para1.width = width;
holder.img_content.setLayoutParams(para1); holder.tv_read = (TextView) convertView
.findViewById(R.id.tv_read);
holder.tv_comment = (TextView) convertView
.findViewById(R.id.tv_comment);
holder.tv_thumbupNum = (TextView) convertView
.findViewById(R.id.tv_thumbupNum);
break; case TYPE_THREE:
convertView = inflater.inflate(R.layout.item_home_three, null);
holder.tv_content = (QSTextView) convertView
.findViewById(R.id.tv_content);
holder.tv_content.setTextColor(Color.GRAY);
holder.tv_title = (QSTextView) convertView
.findViewById(R.id.tv_title);
holder.tv_name = (TextView) convertView
.findViewById(R.id.tv_name);
holder.img_content1 = (ImageView) convertView
.findViewById(R.id.img_content1);
holder.img_content2 = (ImageView) convertView
.findViewById(R.id.img_content2);
holder.img_content3 = (ImageView) convertView
.findViewById(R.id.img_content3);
int w = width / 3;
LayoutParams p = holder.img_content1.getLayoutParams();
p.height = (int)(w*0.7f);
p.width = w;
holder.img_content1.setLayoutParams(p); p = holder.img_content2.getLayoutParams();
p.height = (int)(w*0.7f);
p.width = w;
holder.img_content2.setLayoutParams(p); p = holder.img_content3.getLayoutParams();
p.height = (int)(w*0.7f);
p.width = w;
holder.img_content3.setLayoutParams(p); holder.tv_read = (TextView) convertView
.findViewById(R.id.tv_read);
holder.tv_comment = (TextView) convertView
.findViewById(R.id.tv_comment);
holder.tv_thumbupNum = (TextView) convertView
.findViewById(R.id.tv_thumbupNum);
break; } convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
} switch (type) {
case TYPE_COMMON:
case TYPE_BL:
setCommon(holder, model);
break;
case TYPE_QUESTION:
setQuestion(holder,model);
break;
case TYPE_NONE:
setCase(holder, model);
break;
case TYPE_THREE:
setThree(holder, model);
break;
} return convertView;
} private void setCommon(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > 65) {
content = content.substring(0, 65) + "...";
}
holder.tv_content.setMText(content); String title = entity.getTitle();
int tlength = title.length();
if (tlength > 45) {
title = title.substring(0, 45) + "...";
}
holder.tv_title.setMText(title);
// int height = holder.tv_title.getHeight();
holder.tv_thumbupNum.setText(entity.getThumbupNum());
holder.tv_read.setText(entity.getReadNum());
holder.tv_comment.setText(entity.getCommentNum()); holder.tv_name.setText(entity.getSourceName());
// if (entity.getHead_img() != null && !entity.getHead_img().equals(""))
// {
// ImageLoader.getInstance().displayImage(entity.getHead_img().trim(),
// holder.img_head, options, animateFirstListener);
// } else {
// holder.img_head.setImageResource(R.drawable.pic_head_none_login);
// }
if (entity.getPic1() != null
&& !entity.getPic1().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic1().trim(), holder.img_content,
options, animateFirstListener);
}
} private void setCase(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > 65) {
content = content.substring(0, 65) + "...";
}
holder.tv_content.setMText(content); String title = entity.getTitle();
int tlength = title.length();
if (tlength > 45) {
title = title.substring(0, 45) + "...";
}
holder.tv_title.setMText(title);
// int height = holder.tv_title.getHeight();
holder.tv_thumbupNum.setText(entity.getThumbupNum());
holder.tv_read.setText(entity.getReadNum());
holder.tv_comment.setText(entity.getCommentNum()); holder.tv_name.setText(entity.getSourceName());
if (entity.getPic1() != null
&& !entity.getPic1().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic1().trim(), holder.img_content,
options, animateFirstListener);
}
} private void setThree(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > 65) {
content = content.substring(0, 65) + "...";
}
holder.tv_content.setMText(content); String title = entity.getTitle();
int tlength = title.length();
if (tlength > 45) {
title = title.substring(0, 45) + "...";
}
holder.tv_title.setMText(title);
// int height = holder.tv_title.getHeight();
holder.tv_thumbupNum.setText(entity.getThumbupNum());
holder.tv_read.setText(entity.getReadNum());
holder.tv_comment.setText(entity.getCommentNum()); holder.tv_name.setText(entity.getSourceName()); holder.img_content1.setImageResource(R.drawable.icon_default);
holder.img_content2.setImageResource(R.drawable.icon_default);
holder.img_content3.setImageResource(R.drawable.icon_default);
if (entity.getPic1() != null
&& !entity.getPic1().equals("")) {
holder.img_content1.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic1().trim(), holder.img_content1,
options, animateFirstListener);
}
if (entity.getPic2() != null
&& !entity.getPic2().equals("")) {
holder.img_content1.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic1().trim(), holder.img_content2,
options, animateFirstListener);
}
if (entity.getPic3() != null
&& !entity.getPic3().equals("")) {
holder.img_content1.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic1().trim(), holder.img_content3,
options, animateFirstListener);
}
} private void setQuestion(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > 65) {
content = content.substring(0, 65) + "...";
}
holder.tv_content.setMText(content); String title = entity.getTitle();
int tlength = title.length();
if (tlength > 45) {
title = title.substring(0, 45) + "...";
}
holder.tv_title.setMText(title);
// int height = holder.tv_title.getHeight();
holder.tv_thumbupNum.setText(entity.getThumbupNum());
holder.tv_read.setText(entity.getReadNum());
holder.tv_comment.setText(entity.getCommentNum()); holder.tv_name.setText(entity.getSourceName()); } public void setList(List<HomeEdus> list) {
this.list.clear();
this.list.addAll(list);
notifyDataSetChanged();
} static class ViewHolder {
public QSTextView tv_title;
public QSTextView tv_content;
public ImageView img_content;
public TextView tv_name; public TextView tv_read;
public TextView tv_comment;
public TextView tv_thumbupNum; public ImageView img_content1;
public ImageView img_content2;
public ImageView img_content3;
} private static class AnimateFirstDisplayListener extends
SimpleImageLoadingListener { static final List<String> displayedImages = Collections
.synchronizedList(new LinkedList<String>()); @Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
} }
android listview多视图嵌套多视图的更多相关文章
- 详解 anjularjs的ui-route(多视图、视图嵌套、视图传参)
最近整理了一下anjularjs的第三方插件ui-route,在这就以一个demo的形式讲解一下.整片博客均以开头的demo代码为例.下边是个目录,大家可以酌情直接跳转浏览. 1. demo的代码 2 ...
- Android使用Mono c#分段列表视图
下载source code - 21.7 KB 你想知道如何把多个ListView控件放到一个布局中,但是让它们在显示时表现正确吗 多个列表项?你对它们正确滚动有问题吗?这个例子将向你展示如何组合单独 ...
- Android应用开发学习之列表视图
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 列表视图我们会经常用到,可以通过两种方式来创建列表视图,一种方式是直接使用ListView组件创建,另一种方式是通过 ...
- <Android>列表、网格、画廊视图及适配器的绑定
列表视图和适配器的绑定 列表视图既可以使用ListView组件,也可以继承ListActivity.显示可以是ArrayAdapter,也可以是游标SimpleCursorAdapter,还可以是继承 ...
- asp.net mvc视图中嵌套分部视图
asp.net mvc中Layout相当于webForm中母版页,分部视图相当于webForm中的用户控件. 下面例子是一个视图如何嵌套分部视图: A是分部视图,B是一般视图(A,B中的代码省略) 我 ...
- Android应用开发学习之表格视图
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来学习一个使用表格视图的程序,下图是该程序的运行效果: 该程序主Activity文件内容如下: packag ...
- Android 学习手札(三) 视图(View)
在Android 系统红,任何可视化组件都需要从android.view.View类继承.可以使用两种方式创建View对象. · 一种方式是使用XML来配置View的相关属性,然后使用相应的方法来装载 ...
- ui-router多视图+嵌套视图+传参综合练习
ui-router多视图:页面上存在的多个ui-view,它们以名字区分: 嵌套视图:一个ui-view的一个状态下对应了一个html,这个html里面又有一个ui-view. 视图之间传参:用ui. ...
- 使用XIB实现嵌套自定义视图
在进行iOS开发的过程中,对于一些复杂的界面,我们可以通过Interface Builder这个Xcode集成的可视化界面编辑工具在完成,这回节省大部分时间以及代码量.它的使用方法这里不做介绍了,这次 ...
随机推荐
- Bootstrap Magic – 轻松创建自己的 Bootstrap 主题
Bootstrap Magic 是一款基于 Bootstrap 和 AngularJS 的主题创建工具.您可以轻松地创建您自己的 Twitter Bootstrap 主题,可以立即看到你的内容变化.您 ...
- 微信js SDK接口
微信JS-SDK说明文档 http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html 一.微信登录功能 在进行微信OAut ...
- 【转载】各浏览器CSS兼容问题
CSS对浏览器的兼容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理方法并 整理了一下.对于web2.0的过度,请尽量用xhtml ...
- 交换排序---冒泡排序算法(Javascript版)
比较相邻的元素.如果第一个比第二个大,就交换他们两个.对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应该会是最大的数.针对所有的元素重复以上的步骤,除了最后一个.持续 ...
- Web API应用架构设计分析(1)
Web API 是一种应用接口框架,它能够构建HTTP服务以支撑更广泛的客户端(包括浏览器,手机和平板电脑等移动设备)的框架, ASP.NET Web API 是一种用于在 .NET Framewor ...
- iOS阶段学习第15天笔记(NSDictionary与NSMutableDictionary 字典)
iOS学习(OC语言)知识点整理 一.OC中的字典 1)字典:是一个容器对象,元素是以键-值对(key-value)形式存放的,key和value是任意类型的对象,key是唯一的,value可以重复 ...
- 反编译APK文件
有时源代码丢失了,这时如果有apk文件的话,是可以对apk文件反编译得到源文件的,本文介绍一下简单的反编译apk文件的过程. 1.工具 反编译apk需要的工具有两个:apk2java和apktool, ...
- 2016年湖南省第十二届大学生计算机程序设计竞赛Problem A 2016 找规律归类
Problem A: 2016 Time Limit: 5 Sec Memory Limit: 128 MB Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) ...
- LGLTagsView
做项目的时候经常会用到标签,比如说现在很多项目中搜索历史用标签展示 和 选择某个产品的不同属性用标签展示....网上的有很多封装好的标签,但是作为一个上进的程序员,都希望能有一个自己写的.其实也是一种 ...
- [asp.net mvc 奇淫巧技] 01 - 封装上下文 - 在View中获取自定义的上下文
我们在asp.net 开发中已经封装了最强大的HttpContext,我们可以在HttpContext中可以获取到几乎任何想获取的东西,也可以在HttpContext写入需要返回客户端的信息.但是这些 ...