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中只有一张图片会正常显示,但是如果有两张或两张以上的图片的时候, ...
随机推荐
- Archlinux里面安装VMware Tools
用虚拟机学习linux确实很方便,但是和主机的文件共享是个大问题,VMWARE TOOLS可以很好的解决这个问题,但是在ARCH里却不能向大多数linux那样方便的安装,在查了很多帖子试了无数遍之后, ...
- Android handler Thread 修改UI Demo
/********************************************************************** * Android handler Thread 修改U ...
- SQL Server 外键约束的例子
外键约束的测试表与测试数据 -- 创建测试主表. ID 是主键. CREATE TABLE test_main ( id INT, value ), PRIMARY KEY(id) ); -- 创建测 ...
- 9Patch在Android平台的应用
- 【idea】移动下载站
硬件: 1.Mac或 Linux台 2.300M 无线TP-LINK TL-WR802N AP无密码,与 Mac 同一个网段,Mac开 rails 应用 扫一扫页面,手机下载.OK Mac 搭建ROR ...
- oracle 启用归档日志
Oracle可以运行在2种模式下:归档模式(archivelog)和非归档模式(noarchivelog) 归档模式可以提高Oracle数据库的可恢复性,生产数据库都应该运行在此模式下,归档模式应该和 ...
- ffmpeg常见命令
一.安装 下载ffmpeg,解压之后配置环境变量即为安装 打开dos界面,进入目标文件夹例如:E:/ cd E:\BaiduYunDownload\ffmpeg\ffmpeg_simple ...
- Spark生态之Spark BlinkDB
- hdoj 5194 DZY Loves Balls【规律&&gcd】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5194 题意:给你n个黑球,m个白球,每次从中随机抽取一个,如果抽到黑球记为1如果抽出来白球记为0,让你 ...
- IOS多线程知识总结/队列概念/GCD/主队列/并行队列/全局队列/主队列/串行队列/同步任务/异步任务区别(附代码)
进程:正在进行中的程序被称为进程,负责程序运行的内存分配;每一个进程都有自己独立的虚拟内存空间 线程:线程是进程中一个独立的执行路径(控制单元);一个进程中至少包含一条线程,即主线程 队列 dispa ...