1.MaActivity.class
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import com.google.gson.Gson;
import com.hao.happyshoppingapp.R;
import com.hao.happyshoppingapp.R.layout;
import com.hao.happyshoppingapp.R.menu;
import com.seven.adapter.Category_Saft_Apdapter;
import com.seven.adapter.LookAll_Apdapter;
import com.seven.bean.Data2;
import com.seven.bean.Data2.MyData;
import com.seven.utils.StreamUtils;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
/**
* 查看所有商品界面
* @author 小武
*
*/
public class LookAllActivity extends Activity {
private GridView look_gridView;
private ArrayList<MyData> data;
private ImageButton iv_title_slide;
private TextView tv_app_title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_look_all);
// 初始化
initView();
}
/**
* 初始化
*/
private void initView() {
iv_title_slide = (ImageButton) findViewById(R.id.iv_title_slide);// 返回
tv_app_title = (TextView) findViewById(R.id.tv_app_title);// 标题
look_gridView = (GridView) findViewById(R.id.look_gridView);
MyAsyncTask task = new MyAsyncTask();
task.execute("http://m.yunifang.com/yunifang/mobile/goods/getall?random=87749&encode=ac6bd45b8f50b626a6843b294af8fed5");
// 查看所有商品
tv_app_title.setText(R.string.look_all);
// 返回
iv_title_slide.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
// 从右到左动画
overridePendingTransition(R.anim.anim_in_back,
R.anim.anim_out_back);
}
});
// look_gridView监听
look_gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(LookAllActivity.this,
Detail_Activity.class);// 设置跳转详情界面
intent.putExtra("goods_img", data.get(position).goods_img);// 传递商品图片
intent.putExtra("goods_name", data.get(position).goods_name);// 传递商品价格
intent.putExtra("market_price", data.get(position).market_price);// 传递商品原价
intent.putExtra("shop_price", data.get(position).shop_price);// 传递商品优惠价
intent.putExtra("id", data.get(position).id);// 传递商品id
startActivity(intent);// 启动跳转
// 交互透明效果
overridePendingTransition(R.anim.jump_in, R.anim.jump_out);
}
});
}
class MyAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
URL url = new URL(params[0]);
HttpURLConnection openConnection = (HttpURLConnection) url
.openConnection();
openConnection.setConnectTimeout(5000);
openConnection.setReadTimeout(5000);
int responseCode = openConnection.getResponseCode();
if (responseCode == 200) {
InputStream inputStream = openConnection.getInputStream();
StreamUtils streamUtils = new StreamUtils();
String parseStream = streamUtils.parseSteam(inputStream);
return parseStream;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Gson gson = new Gson();
Data2 fromJson = gson.fromJson(result, Data2.class);
data = fromJson.getData();
look_gridView.setAdapter(new LookAll_Apdapter(LookAllActivity.this,
data));
}
}
}
import java.util.ArrayList;
import com.hao.happyshoppingapp.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.seven.bean.Data1.Ad1;
import com.seven.bean.Data1.MyBriefs;
import com.seven.bean.Data2.MyData;
import com.seven.utils.CommonUtils;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
/**
* 主页查看全部商品适配器
*
* @author 小武
*/
public class LookAll_Apdapter extends BaseAdapter {
private Context context;
private ArrayList<MyData> list;
private DisplayImageOptions option;
public LookAll_Apdapter(Context context,ArrayList<MyData> list) {
// TODO Auto-generated constructor stub
this.context=context;
this.list=list;
option = CommonUtils.getOption();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//优化
ViewHolder holder=null;
if(convertView==null){
convertView = View.inflate(context, R.layout.category_list_item, null);
holder=new ViewHolder();
holder.title_im = (ImageView) convertView.findViewById(R.id.title_im);
convertView.setTag(holder);
// TextView title_name = (TextView) view.findViewById(R.id.title_name);
// title_name.setText(list.get(position).goods_name);
}else{
holder=(ViewHolder) convertView.getTag();
}
holder.title_im.setScaleType(ScaleType.FIT_XY);
ImageLoader.getInstance().displayImage(list.get(position).goods_img, holder.title_im, option);
return convertView;
}
//优化
class ViewHolder{
ImageView title_im;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/activity_title" />
<GridView
android:id="@+id/look_gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:horizontalSpacing="5dp"
android:numColumns="2"
android:verticalSpacing="50dp" >
</GridView>
</LinearLayout>
4.Detail_Activity详情页
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.format.DateUtils;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.alipay.sdk.pay.demo.PayDemoActivity;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hao.happyshoppingapp.R;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.exception.DbException;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.seven.base.BaseActivity;
import com.seven.bean.CollectData;
import com.seven.bean.GoodsBean;
import com.seven.bean.GoodsContextBean;
import com.seven.bean.MyActivity;
import com.seven.bean.MyCar;
import com.seven.bean.MyComments;
import com.seven.dao.CarDao;
import com.seven.dao.SqlDao;
import com.seven.utils.BabyPopWindow.OnItemClickListener;
import com.seven.utils.CommonUtils;
import com.seven.utils.GetDataUtils;
import com.seven.utils.MySQLite;
import com.seven.utils.Urls;
/**
* 商品详情类
* @author 小武
*
*/
public class Detail_Activity extends BaseActivity implements OnClickListener {
private ImageView title_im;
private TextView title_name;
private DisplayImageOptions option;
private ImageButton iv_title_slide;
private TextView tv_app_title;
private TextView title_shop;
private TextView title_market;
private ImageView im_shoucang;
private TextView tv_shoucang;
private ArrayList<MyActivity> alist = new ArrayList<MyActivity>();
private TextView tv_hailiang;
private TextView tv_gouwu;
private TextView tv_shujia;
private TextView tv_xiao;
private TextView tv_shou;
private GoodsBean goodsBean;// 主bean
private LinearLayout linearLayout;
private ViewPager viewPager;
private MySQLite mySQLite;
private CarDao dao;
/** 判断是否点击的立即购买按钮 */
boolean isClickBuy = false;
/** 弹出商品订单信息详情 */
private com.seven.utils.BabyPopWindow popWindow;
/** 用于设置背景暗淡 */
private LinearLayout all_choice_layout = null;
private OnItemClickListener listener;
private TextView tv_shangbt;
private TextView tv_fubt;
private TextView tv_baobt;
private TextView tv_gongbt;
private TextView tv_guibt;
private TextView tv_ping;
private ListView listView;
private ListView listView_c;
private SharedPreferences sharedPreferences;
// 创造收藏的数据库
private DbUtils db;
// 当前跳转过来的bean
private CollectData mCollectData;
private String market_price;
public static SqlDao dao1;
public static String goods_img;
public static String goods_name;
public static String id;
public static String shop_price;
public static int count = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_);
// 初始化方法
initView();
// 创建data对象,解析数据
getData data = new getData();
dao1 = new SqlDao(this);
// 拼接字符串
String url = Urls.HOME_URL_Detail + "&id=" + id;
// 设置路径
data.getSourseFromNet(url);
// 数据库
mySQLite = new MySQLite(this);
dao = new CarDao(this);
// 开始遍历数据库中
try {
getDbItem();
} catch (DbException e1) {
e1.printStackTrace();
}
}
/**
* DButils的遍历方法
*
* @throws DbException
*/
private void getDbItem() throws DbException {
// TODO Auto-generated method stub
// 从数据库中查找
List<CollectData> findAll = db.findAll(CollectData.class);
// 可以从数据库中查询到数据并设置收藏或取消收藏
if (findAll != null) {
for (CollectData collectData : findAll) {
// 遍历集合如果里面数据库中保存的数据和传过来的地址一致,将图标换掉
if (collectData.getUrl().equals(Urls.HOME_URL_Detail + id)) {
// 开始保存bean
mCollectData = collectData;
// 开始获取里面的布尔值
if (mCollectData.isFlag()) {
im_shoucang.setImageResource(R.drawable.collectioned);
tv_shoucang.setText("已收藏");
isClickBuy = true;
}// 当前状态是未选中状态(数据库中有数据)
else {
im_shoucang.setImageResource(R.drawable.collection);
tv_shoucang.setText("收藏");
isClickBuy = false;
}
return;
} else {
// 数据库中没有这条属性,但是数据库中已经有数据
mCollectData = new CollectData(false, Urls.HOME_URL_Detail+
"&id=" + id);
// 状态值
isClickBuy = false;
}
}
} else {
// 并且创建对象(最后保存到数据库中)
mCollectData = new CollectData(false, Urls.HOME_URL_Detail+"&id=" + id);
// 状态值
isClickBuy = false;
}
}
/**
* 初始化方法
*/
private void initView() {
sharedPreferences = getSharedPreferences("king", MODE_PRIVATE);// 创建sharedPreferences保存数据
Intent intent = getIntent();// 创建intent
option = CommonUtils.getOption();// 图片缓存机制
id = intent.getStringExtra("id");
Toast.makeText(Detail_Activity.this, id + "------------------", 0)
.show();
goods_img = intent.getStringExtra("goods_img");// 获取商品图片
goods_name = intent.getStringExtra("goods_name");// 获取商品名称
market_price = intent.getStringExtra("market_price");// 获取商品原价
shop_price = intent.getStringExtra("shop_price");// 获取商品优惠价
title_im = (ImageView) findViewById(R.id.title_im);// 商品图片
title_name = (TextView) findViewById(R.id.title_name);// 商品名称
title_shop = (TextView) findViewById(R.id.title_shop);// 商品优惠价
title_market = (TextView) findViewById(R.id.title_market);// 商品原价
iv_title_slide = (ImageButton) findViewById(R.id.iv_title_slide);// 返回
tv_app_title = (TextView) findViewById(R.id.tv_app_title);// 标题
im_shoucang = (ImageView) findViewById(R.id.im_shoucang);// 收藏图片
tv_shoucang = (TextView) findViewById(R.id.tv_shoucang);// 收藏文字
Button bt_car = (Button) findViewById(R.id.bt_car);// 加入购物车
Button bt_shopping = (Button) findViewById(R.id.bt_shopping);// 立即购买
ImageButton ib_kf = (ImageButton) findViewById(R.id.ib_kf);// 客服图片
TextView tv_kf = (TextView) findViewById(R.id.tv_kf);// 客服文字
Button share_bt = (Button) findViewById(R.id.share_bt);// 分享
tv_shujia = (TextView) findViewById(R.id.tv_shujia);// 暑假
tv_hailiang = (TextView) findViewById(R.id.tv_hailiang);// 海量
tv_gouwu = (TextView) findViewById(R.id.tv_gouwu);// 购物
tv_xiao = (TextView) findViewById(R.id.tv_xiao);// 销量
tv_shou = (TextView) findViewById(R.id.tv_shou);// 收藏
tv_ping = (TextView) findViewById(R.id.tv_ping);// 评论数量
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);// 线性布局三个textView
viewPager = (ViewPager) findViewById(R.id.viewPager);
// 设置监听事件
tv_shujia.setOnClickListener(this);
tv_hailiang.setOnClickListener(this);
tv_gouwu.setOnClickListener(this);
ib_kf.setOnClickListener(this);
tv_kf.setOnClickListener(this);
bt_car.setOnClickListener(this);
bt_shopping.setOnClickListener(this);
share_bt.setOnClickListener(this);
popWindow = new com.seven.utils.BabyPopWindow(this);
// popWindow.setOnItemClickListener(this);
// 商品详情标题
tv_app_title.setText(R.string.detail_title);
title_market.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); // 删除线
title_name.setText(goods_name);// 设置商品名称
title_shop.setText(shop_price);// 设置商品优惠价
title_market.setText(market_price);// 设置商品原价
ImageLoader.getInstance().displayImage(goods_img, title_im);// 设置商品图片
// 初始化数据库
db = DbUtils.create(this);
// 定义收藏按钮的监听
onClick();
// 返回
iv_title_slide.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();// 关闭
overridePendingTransition(R.anim.jump_in, R.anim.jump_out);// 交互透明动画跳转界面
}
});
// 创建list集合把View放进来
final ArrayList<View> list = new ArrayList<View>();
View view1 = View.inflate(Detail_Activity.this, R.layout.a, null);
// listView = (ListView) view1.findViewById(R.id.listView);//详情listView
// // 获取其中的字体
// String goodsDesc = goodsBean.getData().getGoods().getGoods_desc();
// // 开始解析图片
// Gson gson = new Gson();
// Type type = new TypeToken<ArrayList<GoodsContextBean>>() {
// }.getType();
// final ArrayList<GoodsContextBean> lists = gson.fromJson(goodsDesc,
// type);
View view2 = View.inflate(Detail_Activity.this, R.layout.b, null);
tv_shangbt = (TextView) view2.findViewById(R.id.tv_shangbt);
tv_fubt = (TextView) view2.findViewById(R.id.tv_fubt);
tv_baobt = (TextView) view2.findViewById(R.id.tv_baobt);
tv_gongbt = (TextView) view2.findViewById(R.id.tv_gongbt);
tv_guibt = (TextView) view2.findViewById(R.id.tv_guibt);
View view3 = View.inflate(Detail_Activity.this, R.layout.c, null);
listView_c = (ListView) view3.findViewById(R.id.listView);
list.add(view1);
list.add(view2);
list.add(view3);
viewPager.setAdapter(new PagerAdapter() {// 适配器
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0 == arg1;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list != null ? list.size() : 0;
}
@Override
public void destroyItem(ViewGroup container, int position,
Object object) {
container.removeView(list.get(position));
}
@Override
public Object instantiateItem(ViewGroup container,
int position) {
View view = list.get(position);
ViewGroup vg = (ViewGroup) view.getParent();
if (vg != null) {
container.removeAllViews();
}
container.addView(view);
return view;
}
});
// 给textview的监听
for (int i = 0; i < 3; i++) {
TextView tv = (TextView) linearLayout.getChildAt(i);
final int y = i;
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
viewPager.setCurrentItem(y);
}
});
}
// viewPager监听
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// 服颜色
for (int i = 0; i < 3; i++) {
TextView tv = (TextView) linearLayout.getChildAt(i);
// 被点中
if (arg0 == i) {
tv.setTextColor(Color.RED);
} else {
tv.setTextColor(Color.BLACK);
}
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
/**
* 收藏按钮监听
*/
private void onClick() {
// TODO Auto-generated method stub
// 定义收藏按钮的监听
im_shoucang.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 开始判断当前的商品是否被收藏
if (isClickBuy) {
// 并将图标更改
im_shoucang.setImageResource(R.drawable.collection);
tv_shoucang.setText("收藏");
// 将状态值改变
isClickBuy = false;
// 开始将对象的布尔值给改变
mCollectData.setFlag(false);
// 开始改变对象的值
if (mCollectData.getId() == 0) {
// 保存,等于0代表数据库没有当前的对象
try {
db.save(mCollectData);
} catch (DbException e) {
e.printStackTrace();
}
} else {
// 代表数据库中由当前数据
try {
db.update(mCollectData, "flag");
} catch (DbException e) {
e.printStackTrace();
}
}
Toast.makeText(Detail_Activity.this, "取消收藏",
Toast.LENGTH_SHORT).show();
} else {
// 需要将状态值改变成收藏
mCollectData.setFlag(true);
isClickBuy = true;
// 并将图标更改
im_shoucang.setImageResource(R.drawable.collectioned);
tv_shoucang.setText("已收藏");
if (mCollectData.getId() == 0) {
// 保存,等于0代表数据库没有当前的对象
try {
db.save(mCollectData);
} catch (DbException e) {
e.printStackTrace();
}
} else {
// 代表数据库中由当前数据
try {
db.update(mCollectData, "flag");
} catch (DbException e) {
e.printStackTrace();
}
}
Toast.makeText(Detail_Activity.this, "收藏成功",
Toast.LENGTH_SHORT).show();
}
}
});
}
// 请求数据
class getData extends GetDataUtils {
@Override
public void getStringSourse(String result) {
Gson gson = new Gson();
goodsBean = gson.fromJson(result, GoodsBean.class);
// ids=goodsBean.getData().getGoods().getId();
// alist.addAll(goodsBean.getData().getActivity());
// tv_shujia.setText(goodsBean.getData().getActivity().get(0).title);//
// 设置运费
// tv_hailiang.setText(goodsBean.getData().getActivity().get(1).title);//
// 设置海量
// tv_gouwu.setText(goodsBean.getData().getActivity().get(2).title);//
// 设置购物
tv_xiao.setText(goodsBean.getData().getGoods().getSales_volume());// 销量
tv_shou.setText(goodsBean.getData().getGoods().getCollect_count());// 收藏
tv_shangbt.setText(goodsBean.getData().getGoods().getAttributes()
.get(0).getAttr_name()
+ "\t\t\t"
+ goodsBean.getData().getGoods().getAttributes().get(0)
.getAttr_value());// 设置上市时间
tv_fubt.setText(goodsBean.getData().getGoods().getAttributes()
.get(1).getAttr_name()
+ "\t\t\t"
+ goodsBean.getData().getGoods().getAttributes().get(1)
.getAttr_value());// 设置适合皮肤
tv_baobt.setText(goodsBean.getData().getGoods().getAttributes()
.get(2).getAttr_name()
+ "\t\t\t\t"
+ goodsBean.getData().getGoods().getAttributes().get(2)
.getAttr_value());// 设置保质期
tv_gongbt.setText(goodsBean.getData().getGoods().getAttributes()
.get(3).getAttr_name()
+ "\t\t\t"
+ goodsBean.getData().getGoods().getAttributes().get(3)
.getAttr_value());// 设置产品功效
tv_guibt.setText(goodsBean.getData().getGoods().getAttributes()
.get(4).getAttr_name()
+ "\t\t\t"
+ goodsBean.getData().getGoods().getAttributes().get(4)
.getAttr_value());// 设置产品规格
tv_ping.setText("评论(" + goodsBean.getData().getCommentNumber()
+ ")");// 设置评价数量
// 开始适配评价
final ArrayList<MyComments> comments = goodsBean.getData()
.getComments();
listView_c.setAdapter(new BaseAdapter() {// 评论内容适配器
@SuppressLint("ViewHolder")
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
View view = View.inflate(Detail_Activity.this,
R.layout.listc_item, null);
// ImageView imageView = (ImageView)
// view.findViewById(R.id.imageView);
TextView tv_name = (TextView) view
.findViewById(R.id.tv_name);
TextView tv_time = (TextView) view
.findViewById(R.id.tv_time);
tv_name.setText(comments.get(position).content);// 设置评论内容
tv_time.setText(comments.get(position).createtime);// 设置评论时间
return view;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return comments.get(position);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return comments.size();
}
});
}
}
/** 设置监听 */
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
/** 控制背景变暗 0变暗 1变亮 */
public void setBackgroundBlack(View view, int what) {
switch (what) {
case 0:
view.setVisibility(View.VISIBLE);
break;
case 1:
view.setVisibility(View.GONE);
break;
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bt_car:// 加入购物车
// 添加购物车
// isClickBuy = false;
// setBackgroundBlack(all_choice_layout, 0);
popWindow.showAsDropDown(v);
break;
case R.id.bt_shopping:// 立即购物
//跳转到支付界面
Intent intent3 = new Intent(Detail_Activity.this, PayDemoActivity.class);
startActivity(intent3);
break;
case R.id.ib_kf:// 客服图片
Toast.makeText(Detail_Activity.this, "客服", 0).show();
break;
case R.id.tv_kf:// 客服文字
Toast.makeText(Detail_Activity.this, "客服", 0).show();
break;
case R.id.share_bt:// 分享
Toast.makeText(Detail_Activity.this, "分享", 0).show();
break;
case R.id.tv_shujia:// 暑假
Toast.makeText(Detail_Activity.this, "暑假", 0).show();
Intent intent = new Intent(Detail_Activity.this, Web_Activity.class);
intent.putExtra("ji_url", goodsBean.getData().getActivity().get(0)
.getDescription());
startActivity(intent);
break;
case R.id.tv_hailiang:// 海量
Toast.makeText(Detail_Activity.this, "海量", 0).show();
Intent intent1 = new Intent(Detail_Activity.this,
Web_Activity.class);// 跳转到web界面
intent1.putExtra("ji_url", goodsBean.getData().getActivity().get(1)
.getDescription());
startActivity(intent1);
break;
case R.id.tv_gouwu:// 购物
Toast.makeText(Detail_Activity.this, "购物", 0).show();
Intent intent2 = new Intent(Detail_Activity.this,
Web_Activity.class);
intent2.putExtra("ji_url", goodsBean.getData().getActivity().get(2)
.getDescription());
startActivity(intent2);
break;
default:
break;
}
}
}
5.详情页布局activity_detail_.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/activity_title" />
<!-- ScrollView和LinearLayout设置比例7:1,xml布局和布局可见 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/title_im"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitXY" />
<TextView
android:id="@+id/title_name"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="商品名称" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/title_s1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ¥ "
android:textColor="@color/home_activity" />
<TextView
android:id="@+id/title_shop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
android:textColor="@color/home_activity"
android:textSize="@dimen/home_listView_price" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/title_s2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ¥ " />
<TextView
android:id="@+id/title_market"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999" />
</LinearLayout>
<ImageView
android:id="@+id/im_quan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="@drawable/coupons" />
<ImageView
android:id="@+id/im_di"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="@drawable/pledge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="115dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/im_shoucang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/collection"
/>
<TextView
android:id="@+id/tv_shoucang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="收藏" />
</LinearLayout>
</LinearLayout>
<!-- 运费销量收藏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1" >
<TextView
android:id="@+id/yunfei"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="运费" />
<TextView
android:id="@+id/tv_yun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="包邮"
android:textColor="@color/menu_layout_address" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/xiaoliang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="销量" />
<TextView
android:id="@+id/tv_xiao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="999"
android:textColor="@color/menu_layout_address" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/shoucang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收藏" />
<TextView
android:id="@+id/tv_shou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="988"
android:textColor="@color/menu_layout_address" />
</LinearLayout>
</LinearLayout>
<!-- 暑假海量购物 -->
<LinearLayout style="@style/leba_bg_layout" >
<LinearLayout style="@style/leba_bg_single_layout" >
<TextView
android:id="@+id/tv_shujia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12.0dip"
android:layout_weight="1.0"
android:text="暑假放假:888"
android:textColor="#ff333333"
android:textSize="16.0dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12.0dip"
android:src="@drawable/setting_arrow" />
</LinearLayout>
</LinearLayout>
<!-- 海量赠品 -->
<LinearLayout style="@style/leba_bg_layout" >
<!-- 海量赠品 -->
<LinearLayout style="@style/leba_bg_top_layout" >
<TextView
android:id="@+id/tv_hailiang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12.0dip"
android:layout_weight="1.0"
android:text="海量赠品:888"
android:textColor="#ff333333"
android:textSize="16.0dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12.0dip"
android:src="@drawable/setting_arrow" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1.0px"
android:background="@drawable/leba_shape_line" />
<!-- 购物须知 -->
<LinearLayout style="@style/leba_bg_bottom_layout" >
<TextView
android:id="@+id/tv_gouwu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12.0dip"
android:layout_weight="1.0"
android:text="购物须知:888"
android:textColor="#ff333333"
android:textSize="16.0dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12.0dip"
android:src="@drawable/setting_arrow" />
</LinearLayout>
</LinearLayout>
<!-- 产品详情,参数,评价 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#ffffff" >
<TextView
android:id="@+id/tv_xiang"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:layout_weight="1"
android:text="产品详情"
android:textColor="@color/home_activity" />
<TextView
android:id="@+id/tv_can"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="产品参数" />
<TextView
android:id="@+id/tv_ping"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="评论(889)" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="500dp" >
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</ScrollView>
<!-- 客服,加入购物车,立即购物 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageButton
android:id="@+id/ib_kf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/public_contact_service_icon" />
<TextView
android:id="@+id/tv_kf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="客服" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dp" >
<Button
android:id="@+id/bt_car"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#ff6600"
android:text="加入购物车" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" >
<Button
android:id="@+id/bt_shopping"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#ff6666"
android:text="立即购物" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
anim_in_back.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0%p"
android:duration="500" />
</set>
anim_in_back.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="500" />
</set>
7.实体类Data2
import java.io.Serializable;
import java.util.ArrayList;
/**
* @category 小武
*
*/
public class Data2 implements Serializable {
public ArrayList<MyData> data;
public ArrayList<MyData> getData() {
return data;
}
public void setData(ArrayList<MyData> data) {
this.data = data;
}
public class MyData implements Serializable {
public String goods_img;
public String goods_name;
public String market_price;
public String shop_price;
public String sales_volume;
public String id;
}
@Override
public String toString() {
return "Data1 [data=" + data + "]";
}
}