Android listview多视图嵌套多视图

 更新时间:2016年02月01日 15:21:18   作者:零点零的距离  
这篇文章主要介绍了Android listview多视图嵌套多视图 的相关资料,需要的朋友可以参考下

首先给大家展示下效果图:

public class HomeEduMoreAdapter extends BaseAdapter {
private final String TAG = "HomeEduMoreAdapter";
private static final int TYPE_COMMON = ;
private static final int TYPE_BL = ;
private static final int TYPE_NONE = ;
private static final int TYPE_THREE = ;
private static final int TYPE_QUESTION = ;
private int TYPE_COUNT = ;
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_).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.getPic() == null || edus.getPic().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 > && imgNum < ) {
result = TYPE_COMMON;
} else if (imgNum != null && imgNum >= ) {
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() / ;
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 para = holder.img_content.getLayoutParams();
para.height = height;
para.width = width;
holder.img_content.setLayoutParams(para);
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_content = (ImageView) convertView
.findViewById(R.id.img_content);
holder.img_content = (ImageView) convertView
.findViewById(R.id.img_content);
holder.img_content = (ImageView) convertView
.findViewById(R.id.img_content);
int w = width / ;
LayoutParams p = holder.img_content.getLayoutParams();
p.height = (int)(w*.f);
p.width = w;
holder.img_content.setLayoutParams(p);
p = holder.img_content.getLayoutParams();
p.height = (int)(w*.f);
p.width = w;
holder.img_content.setLayoutParams(p);
p = holder.img_content.getLayoutParams();
p.height = (int)(w*.f);
p.width = w;
holder.img_content.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 > ) {
content = content.substring(, ) + "...";
}
holder.tv_content.setMText(content);
String title = entity.getTitle();
int tlength = title.length();
if (tlength > ) {
title = title.substring(, ) + "...";
}
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.getPic() != null
&& !entity.getPic().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic().trim(), holder.img_content,
options, animateFirstListener);
}
}
private void setCase(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > ) {
content = content.substring(, ) + "...";
}
holder.tv_content.setMText(content);
String title = entity.getTitle();
int tlength = title.length();
if (tlength > ) {
title = title.substring(, ) + "...";
}
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.getPic() != null
&& !entity.getPic().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic().trim(), holder.img_content,
options, animateFirstListener);
}
}
private void setThree(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > ) {
content = content.substring(, ) + "...";
}
holder.tv_content.setMText(content);
String title = entity.getTitle();
int tlength = title.length();
if (tlength > ) {
title = title.substring(, ) + "...";
}
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_content.setImageResource(R.drawable.icon_default);
holder.img_content.setImageResource(R.drawable.icon_default);
holder.img_content.setImageResource(R.drawable.icon_default);
if (entity.getPic() != null
&& !entity.getPic().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic().trim(), holder.img_content,
options, animateFirstListener);
}
if (entity.getPic() != null
&& !entity.getPic().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic().trim(), holder.img_content,
options, animateFirstListener);
}
if (entity.getPic() != null
&& !entity.getPic().equals("")) {
holder.img_content.setBackground(null);
ImageLoader.getInstance().displayImage(
entity.getPic().trim(), holder.img_content,
options, animateFirstListener);
}
}
private void setQuestion(ViewHolder holder, HomeEdus entity) {
String content = entity.getDesc();
int clength = content.length();
if (clength > ) {
content = content.substring(, ) + "...";
}
holder.tv_content.setMText(content);
String title = entity.getTitle();
int tlength = title.length();
if (tlength > ) {
title = title.substring(, ) + "...";
}
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_content;
public ImageView img_content;
public ImageView img_content;
}
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, );
displayedImages.add(imageUri);
}
}
}
}
}

相关文章

  • Android如何通过手机自动获取短信验证码

    Android如何通过手机自动获取短信验证码

    注册帐号时,经常需要手机获取验证码,Android如何通过手机自动获取短信验证码,下面看看小编给大家分享的一段代码,感兴趣的小伙伴们可以参考一下
    2016-03-03
  • Android编程使用HTTP协议与TCP协议实现上传文件的方法

    Android编程使用HTTP协议与TCP协议实现上传文件的方法

    这篇文章主要介绍了Android编程使用HTTP协议与TCP协议实现上传文件的方法,结合实例形式较为详细的分析了Android使用HTTP协议与TCP协议的具体步骤与实现文件传输的相关技巧,需要的朋友可以参考下
    2016-01-01
  • Android(2.2/2.3系统)Gallery解决默认和横竖屏切换选中状态问题

    Android(2.2/2.3系统)Gallery解决默认和横竖屏切换选中状态问题

    本文主要介绍Android Gallery,在Android开发过程中肯定会遇到版本不同,在开发过程中需要调整的,这里针对Android(2.2/2.3系统版本) Gallery解决默认和横竖屏切换选中状态问题
    2016-07-07
  • Android进度条控件progressbar使用方法详解

    Android进度条控件progressbar使用方法详解

    这篇文章主要为大家详细介绍了Android进度条控件progressbar的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • Android ViewPager加载图片效果

    Android ViewPager加载图片效果

    这篇文章主要为大家详细介绍了Android ViewPager加载图片效果的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-01-01
  • 4种Android屏幕自适应解决方案

    4种Android屏幕自适应解决方案

    在开发android项目的时候,我们常常会考虑这样的问题:为不同的手机屏幕显示出最佳的界面,以提升用户的体验。本文介绍的是4种Android屏幕自适应解决方案,有兴趣的可以了解一下。
    2016-10-10
  • Android电话拨号器实例详解

    Android电话拨号器实例详解

    这篇文章主要为大家详细介绍了Android电话拨号器实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-07-07
  • Android Studio工程引用第三方so文件的方法

    Android Studio工程引用第三方so文件的方法

    这篇文章主要介绍了Android Studio工程引用第三方so文件的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-11-11
  • Android自定义定时闹钟开发

    Android自定义定时闹钟开发

    这篇文章主要为大家详细介绍了Android自定义定时闹钟开发,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-09-09
  • Android性能优化及性能优化工具

    Android性能优化及性能优化工具

    这篇文章主要给大家分享的是Android性能优化及性能优化工具,下面文字会围绕Android性能优化的相关资料详细的展开具体内容,需要的朋友可以参考一下,希望对大家有所帮助
    2021-11-11

最新评论