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中只有一张图片会正常显示,但是如果有两张或两张以上的图片的时候, ...
随机推荐
- 深入分析Cookie的安全性问题
Cookie的目的是为用户带来方便,为网站带来增值,一般情况下不会造成严重的安全威胁.Cookie文件不能作为代码执行,也不会传送病毒,它为用户所专有并只能由创建它的服务器来读取.另外,浏览器一般只允 ...
- Linux power supply class hacking
/*************************************************************************** * Linux power supply cl ...
- UVA 12661 Funny Car Racing 有趣的赛车比赛(最短路,变形)
题意:赛道有n个交叉点,和m条单向路径(有重边),每条路都是周期性关闭的,且通过仍需一段时间.在比赛开始时,所有道路刚好打开,选择进入该道路必须满足“在打开的时间段进入,在关闭之前出来”,即不可在路上 ...
- Flask
#environ:一个包含所有HTTP请求信息的dict对象 #start_response:一个发送HTTP响应的函数 def application(environ, start_response ...
- apache开源项目--Shiro
安全是企业应用中不可缺少的功能,在众多权限框架中,Shiro(其前身是JSecurity)因其简单而又不失强大的特点引起了不少开发者的注 意.随着Grails的关注度越来越高,在Grails社区也出现 ...
- Windows Server 2008文件同步
配置Windows Server 2008文件同步 摘要: 众所周知,Linux系统可以用rsync来实现文件或目录的同步,windows系统下也一样可以.我们现在就用cwRsync来实现wind ...
- Hibernate4.x之映射关系--一对一映射
Hibernate的1-1映射关系主要分为两类: 1.Hibernate基于外键映射的1对1关联关系 对于基于外键的1-1关联,其外键可以存放在任意一边,在需要存放外键一端,增加many-to-one ...
- svc 报“由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。“的HTTP 错误 404.3 – Not Found
原因:系统没有默认为IIS注册WCF服务的svc文件的MIME映射. 解决方法:管理员身份运行C:\Windows\Microsoft.NET\Framework\v3.0\Windows Commu ...
- .net 禁止远程查看应用程序错误的详细信息,服务器上出现应用程序错误
打开页面时出现以下错误 "/"应用程序中的服务器错误. 运行时错误 说明: 服务器上出现应用程序错误.此应用程序的当前自定义错误设置禁止远程查看应用程序错误的详细信息(出于安全 ...
- ubuntu修改主机名和出现问题
修改主机名方法,修改/etc/hostname即可,但是修改完成后,每次sudo都出现警告,警告解决方法如下: Linux 环境, 假设这台机器名字叫dev(机器的hostname), 每次执行sud ...