android124 zhihuibeijing 新闻中心-组图

package com.itheima.zhbj52.base.menudetail; import java.util.ArrayList; import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast; import com.google.gson.Gson;
import com.itheima.zhbj52.R;
import com.itheima.zhbj52.base.BaseMenuDetailPager;
import com.itheima.zhbj52.domain.PhotosData;
import com.itheima.zhbj52.domain.PhotosData.PhotoInfo;
import com.itheima.zhbj52.domain.PhotosData.PhotosInfo;
import com.itheima.zhbj52.global.GlobalContants;
import com.itheima.zhbj52.utils.CacheUtils;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod; /**
* 新闻中心-组图
*/
public class PhotoMenuDetailPager extends BaseMenuDetailPager {
/*public abstract class BaseMenuDetailPager {
public Activity mActivity;
public View mRootView;// 根布局对象
public BaseMenuDetailPager(Activity activity) {
mActivity = activity;
mRootView = initViews();
}
public abstract View initViews();
public void initData() {
}
}*/ private ListView lvPhoto;
private GridView gvPhoto;
private ArrayList<PhotoInfo> mPhotoList;
private PhotoAdapter mAdapter;
private ImageButton btnPhoto; public PhotoMenuDetailPager(Activity activity, ImageButton btnPhoto) {//btnPhoto对象通过构造函数传过来。
super(activity);
this.btnPhoto = btnPhoto;
btnPhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
changeDisplay();
}
});
} @Override
public View initViews() {
View view = View.inflate(mActivity, R.layout.menu_photo_pager, null);
//menu_photo_pager.xml
/*<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/lv_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#fff" 背景色为白色
android:divider="@null" /> 没有分割线
<GridView
android:id="@+id/gv_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2" 设置为2列
android:visibility="gone" /> 默认隐藏。点击可以切换用ListView或者GridView。
</FrameLayout>*/ lvPhoto = (ListView) view.findViewById(R.id.lv_photo);
gvPhoto = (GridView) view.findViewById(R.id.gv_photo);
return view;
} @Override
public void initData() {
String cache = CacheUtils
.getCache(GlobalContants.PHOTOS_URL, mActivity);
//PHOTOS_URL = "http://10.0.2.2:8080/zhbj/photos/photos_1.json";
if (!TextUtils.isEmpty(cache)) {
}
getDataFromServer();
} private void getDataFromServer() {
HttpUtils utils = new HttpUtils();
utils.send(HttpMethod.GET, GlobalContants.PHOTOS_URL,
new RequestCallBack<String>() {
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
String result = (String) responseInfo.result;
parseData(result);
// 设置缓存
CacheUtils.setCache(GlobalContants.PHOTOS_URL, result,
mActivity);
} @Override
public void onFailure(HttpException error, String msg) {
Toast.makeText(mActivity, msg, Toast.LENGTH_SHORT)
.show();
error.printStackTrace();
}
});
} protected void parseData(String result) {
Gson gson = new Gson();
PhotosData data = gson.fromJson(result, PhotosData.class);
/*public class PhotosData {
public int retcode;
public PhotosInfo data;
public class PhotosInfo {
public String title;
public ArrayList<PhotoInfo> news;
}
public class PhotoInfo {
public String id;
public String listimage;
public String pubdate;
public String title;
public String type;
public String url;
}
}*/
mPhotoList = data.data.news;// 获取组图列表集合 if (mPhotoList != null) {
mAdapter = new PhotoAdapter();
lvPhoto.setAdapter(mAdapter);//使用同一个mAdapter
gvPhoto.setAdapter(mAdapter);
}
} class PhotoAdapter extends BaseAdapter { private BitmapUtils utils; public PhotoAdapter() {
utils = new BitmapUtils(mActivity);
utils.configDefaultLoadingImage(R.drawable.news_pic_default);//默认加载图片
} @Override
public int getCount() {
return mPhotoList.size();
} @Override
public PhotoInfo getItem(int position) {
return mPhotoList.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = View.inflate(mActivity, R.layout.list_photo_item,null);
/*<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/pic_list_item_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="180dp"
android:scaleType="centerCrop"
android:src="@drawable/news_pic_default" />
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="标题"
android:singleLine="true"
android:textColor="#000"
android:textSize="22sp" />
</LinearLayout>
</LinearLayout>*/
holder = new ViewHolder();
holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
holder.ivPic = (ImageView) convertView.findViewById(R.id.iv_pic); convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
PhotoInfo item = getItem(position);
holder.tvTitle.setText(item.title);
utils.display(holder.ivPic, item.listimage);//加载图片,默认BitmapUtils对图片提供了缓存。
return convertView;
} } static class ViewHolder {
public TextView tvTitle;
public ImageView ivPic;
} private boolean isListDisplay = true;// 是否是列表展示 /**
* 切换展现方式
*/
private void changeDisplay() {
if (isListDisplay) {
isListDisplay = false;
lvPhoto.setVisibility(View.GONE);
gvPhoto.setVisibility(View.VISIBLE); btnPhoto.setImageResource(R.drawable.icon_pic_list_type); } else {
isListDisplay = true;
lvPhoto.setVisibility(View.VISIBLE);
gvPhoto.setVisibility(View.GONE); btnPhoto.setImageResource(R.drawable.icon_pic_grid_type);
}
}
}
android124 zhihuibeijing 新闻中心-组图的更多相关文章
- android124 zhihuibeijing 新闻中心-新闻 -北京页签 下拉刷新
缓存工具类:以url为key,json数据为value, package com.itheima.zhbj52.utils; import com.itheima.zhbj52.global.Glob ...
- android122 zhihuibeijing 新闻中心NewsCenterPager加载网络数据实现
新闻中心NewsCenterPager.java package com.itheima.zhbj52.base.impl; import java.util.ArrayList; import an ...
- android123 zhihuibeijing 新闻中心-新闻 页签 ViewPagerIndicator实现
## ViewPagerIndicator ## 使用导入ViewPagerIndicator库的方式相当于可以改源码,打包编译Eclips可以自动完成. ViewPager指针项目,在使用ViewP ...
- android 项目学习随笔十七(ListView、GridView显示组图)
ListView.GridView显示组图,处理机制相同 <?xml version="1.0" encoding="utf-8"?> <Li ...
- phpcms图片模型调用组图的问题
phpcms里面有个图片模型,之前一直没有用过,之前用的轮播图是用文章+缩略图+推荐位实现的 今天看了一下图片模型添加内容的地方,和平常的文章相比多了一个组图的地方:
- 『摄影欣赏』16幅 Romantic 风格照片欣赏【组图】
今天,我们将继续分享人类情感的系列文章.爱是人类最重要的感觉,也可能是各种形式的艺术(电影,音乐,书,画等)最常表达的主题 .这里有40个最美丽的爱的照片,将激励和给你一个全新的视觉角度为这种情绪.我 ...
- 轻奢品牌全面崛起 Coach、UGG等纷纷抢滩新兴市场_新闻中心_赢商网
轻奢品牌全面崛起 Coach.UGG等纷纷抢滩新兴市场_新闻中心_赢商网 轻奢品牌全面崛起 Coach.UGG等纷纷抢滩新兴市场
- 【图文】雪佛兰Suburban 美国特工标准座驾_新闻中心_易车网
[图文]雪佛兰Suburban 美国特工标准座驾_新闻中心_易车网 雪佛兰Suburban 美国特工标准座驾
- phpcms v9手机站不支持组图($pictureurls)的修改
phpcms v9自带的手机门户网站,有时候我们需要用到组图功能$pictureurls,我在做的时候发现,如果$pictureurls中只有一张图片会正常显示,但是如果有两张或两张以上的图片的时候, ...
随机推荐
- BZOJ3258: 秘密任务
题解: 其实就是一个简单的最小割判断是否唯一解... 可是我写了一上午还没过...T_T 把1-n的最短路上的边提出来做最小割. 然后从s,t分别bfs判断必须在某个割的点.如果有的点没有被bfs到, ...
- Linux 根文件系统制作
1.创建根文件目录 mkdir rootfs(名字是随便取的) 2.创建子目录 cd rootfs mkdir bin dev etc lib proc sbin sys usr mnt tmp va ...
- RMAN 备份与恢复深入解析(二)
RMAN 备份与恢复深入解析(一) http://space.itpub.net/26686207/viewspace-760869 更多精彩内容尽在 www.leonarding.com < ...
- [开发工具] 史上最全系列之开发环境搭建之DDMS
原文链接:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=275774 一.简介 DDMS 的全称是DalvikDebug Mon ...
- c#编程指南(四) 组元(Tuple)
(1).C#语法中一个个问号(?)的运算符是指:可以为 null 的类型. MSDN上面的解释: 在处理数据库和其他包含不可赋值的元素的数据类型时,将 null 赋值给数值类型或布尔型以及日期类型的功 ...
- CSS中的块级元素与行级元素
最近初学CSS时对块级元素与行级元素有时会产生混淆,写篇博客记录一下自己对其的理解. 先从概念上来看: 块级元素 特点:1.每个块级元素都是独自占一行,其后的元素也只能另起一行,并不能两个元素共用一行 ...
- android中Invalidate和postInvalidate的区别
Android中实现view的更新有两组方法,一组是invalidate,另一组是postInvalidate,其中前者是在UI线程自身中使用,而后者在非UI线程中使用. Android提供了Inva ...
- [转] This function or variable may be unsafe
原文:This function or variable may be unsafe,他大姨妈 错误提示: [Error]'fopen' This function or variable may b ...
- 查询Table name, Column name, 拼接执行sql文本, 游标, 存储过程, 临时表
018_Proc_UpdateTranslations.sql: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO if (exists (select ...
- 使用C语言实现二维,三维绘图算法(2)-解析曲面的显示
使用C语言实现二维,三维绘图算法(2)-解析曲面的显示 ---- 引言---- 每次使用OpenGL或DirectX写三维程序的时候, 都有一种隔靴搔痒的感觉, 对于内部的三维算法的实现不甚了解. 其 ...