package com.zqy.myselectorspec;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class RecylerSkuActivity extends Activity implements OnClickListener {
private Button id_put_cart;
private PopupWindow popup;
private View parentView;
private RecyclerView id_myRecyclerView;
private List<SkuBean> datas;
MyrecyclerViewAdapter adater;
private TextView tv_sku,tv_sku_stock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
parentView = LayoutInflater.from(this).inflate(R.layout.activity_recyler_sku, null);
setContentView(parentView);
initData();
initPop();
initView();
}
private void initData() {
datas = new ArrayList<>();
SkuBean skuBean1 = new SkuBean();
List<Bean> list1 = new ArrayList<>();
skuBean1.setTitle("尺寸");
list1.add(new Bean("S", "1"));
list1.add(new Bean("M", "1"));
list1.add(new Bean("L", "1"));
list1.add(new Bean("XL", "1"));
list1.add(new Bean("XXL", "1"));
list1.add(new Bean("XXXL", "1"));
skuBean1.setContent(list1);
datas.add(skuBean1);
SkuBean skuBean2 = new SkuBean();
List<Bean> list2 = new ArrayList<>();
skuBean2.setTitle("颜色");
list2.add(new Bean("红色", "1"));
list2.add(new Bean("橙色", "1"));
list2.add(new Bean("黄色", "1"));
list2.add(new Bean("绿色", "1"));
list2.add(new Bean("青色", "1"));
list2.add(new Bean("蓝色", "1"));
list2.add(new Bean("紫色", "1"));
skuBean2.setContent(list2);
datas.add(skuBean2);
}
//初始化popwindow
private void initPop() {
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int height = wm.getDefaultDisplay().getHeight() * 3 / 4;
LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View contentView = mLayoutInflater.inflate(R.layout.popup_layout, null);// R.layout.pop为 PopupWindow 的布局文件
popup = new PopupWindow(contentView, ViewGroup.LayoutParams.FILL_PARENT, height);
// 使其聚集
popup.setFocusable(true);
// 设置允许在外点击消失
popup.setOutsideTouchable(true);
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popup.setBackgroundDrawable(new BitmapDrawable());
// 设置popWindow的显示和消失动画
popup.setAnimationStyle(R.style.mypopwindow_anim_style);
tv_sku_stock = (TextView) contentView.findViewById(R.id.tv_sku_stock);//已选择的规格选项
tv_sku = (TextView) contentView.findViewById(R.id.tv_sku);//没有选择的规格选项
id_myRecyclerView = (RecyclerView) contentView.findViewById(R.id.id_myRecyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//设置布局管理器
id_myRecyclerView.setLayoutManager(layoutManager);
//设置为垂直布局,这也是默认的
layoutManager.setOrientation(OrientationHelper.VERTICAL);
adater = new MyrecyclerViewAdapter(this, datas);
adater.setItemClickListener(new MyrecyclerViewAdapter.onItemAndGvItemClickListener() {
@Override
public void onItemAndGvItemClick(Bean bean, int position, int gv_position) {
switch (bean.getStates()){
case "0"://选中
datas.get(position).getContent().get(gv_position).setStates("1");
datas.get(position).setChooseNum(false);
updateText();
adater.notifyDataSetChanged();
break;
case "1"://没有选择
for(int i=0;i<datas.get(position).getContent().size();i++){
datas.get(position).getContent().get(i).setStates("1");
}
datas.get(position).getContent().get(gv_position).setStates("0");
datas.get(position).setChooseNum(true);
updateText();
adater.notifyDataSetChanged();
break;
case "2"://不可选
break;
}
}
});
id_myRecyclerView.setAdapter(adater);
}
// 更新数据显示
private void updateText() {
tv_sku_stock.setText("");
tv_sku.setText("");
String skuStr = "";
String skuStockStr = "";
for(int i=0;i<datas.size();i++){
if(datas.get(i).getChooseNum()){//被选中
if(skuStockStr.equals("")){
for(int j=0;j<datas.get(i).getContent().size();j++){
if(datas.get(i).getContent().get(j).getStates().equals("0")){
skuStockStr = datas.get(i).getTitle()+":"+datas.get(i).getContent().get(j).getName();
}
}
}else {
for(int j=0;j<datas.get(i).getContent().size();j++){
if(datas.get(i).getContent().get(j).getStates().equals("0")){
skuStockStr = datas.get(i).getTitle() + ":" + datas.get(i).getContent().get(j).getName() + "," + skuStockStr;
}
}
}
}else{//没有被选中
if(skuStr.equals("")){
skuStr = datas.get(i).getTitle();
}else{
skuStr = datas.get(i).getTitle()+","+skuStr;
}
}
}
if(!skuStr.equals("")){
tv_sku.setText("请选择"+skuStr);
}
if(!skuStockStr.equals("")){
tv_sku_stock.setText("您已选择:"+skuStockStr);
}
}
private void initView() {
id_put_cart = (Button) findViewById(R.id.id_put_cart);//加入购物车
id_put_cart.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.id_put_cart:
int[] location = new int[2];
id_put_cart.getLocationOnScreen(location);
popup.showAtLocation(id_put_cart, Gravity.NO_GRAVITY, location[0], location[1] - popup.getHeight());
break;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
使用recyclerView和GridView实现动态显示商品属性
共74个文件
xml:36个
java:8个
bin:6个
需积分: 5 71 下载量 19 浏览量
2016-10-09
11:05:18
上传
评论
收藏 216KB RAR 举报
温馨提示
在很多的电商的项目当中都有添加购物车的这项功能,而添加购物车功能必不可少的就是选择商品的规格,比如说,尺寸、颜色、口味等等,如果每个商品只有一个规格,那就非常好办,但是由于商品的属性的多样性,也就意味着商品属性的不确定性,所以在编写选择商品规格的时候就不能固定商品属性的选择。由于本人在android方面也是菜鸟一只,当项目需要的时候也是上网去搜索大牛写的关于商品选择规格的实现。。。。。。
资源推荐
资源详情
资源评论
收起资源包目录
MySelectorSpec.rar (74个子文件)
MySelectorSpec
gradlew.bat 2KB
gradlew 5KB
MySelectorSpec.iml 945B
gradle.properties 872B
.gradle
2.10
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 21KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.lock 17B
localClassSetAnalysis.bin 27KB
taskArtifacts
fileHashes.bin 137KB
cache.properties.lock 17B
taskArtifacts.bin 95KB
fileSnapshots.bin 2.09MB
cache.properties 31B
outputFileStates.bin 20KB
app
proguard-rules.pro 663B
src
test
java
com
zqy
myselectorspec
ExampleUnitTest.java 329B
androidTest
java
com
zqy
myselectorspec
ApplicationTest.java 365B
main
res
mipmap-xxxhdpi
ic_launcher.png 10KB
drawable
mipmap-hdpi
ic_launcher.png 3KB
values
colors.xml 214B
strings.xml 80B
styles.xml 692B
dimens.xml 216B
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
anim
pophidden_anim.xml 343B
popshow_anim.xml 344B
layout
gridview_item.xml 789B
activity_recyler_sku.xml 1KB
recycler_item_layout.xml 961B
popup_layout.xml 3KB
xml
shape2.xml 635B
shape1.xml 635B
shape3.xml 635B
values-w820dp
dimens.xml 364B
java
com
zqy
myselectorspec
SkuBean.java 937B
MyrecyclerViewAdapter.java 3KB
SkuAdapter.java 3KB
RecylerSkuActivity.java 7KB
MyGridView.java 936B
Bean.java 588B
AndroidManifest.xml 746B
app.iml 11KB
.gitignore 8B
build.gradle 707B
libs
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 231B
.idea
gradle.xml 739B
runConfigurations.xml 564B
misc.xml 3KB
.name 14B
copyright
profiles_settings.xml 76B
modules.xml 365B
encodings.xml 159B
compiler.xml 686B
workspace.xml 178KB
libraries
support_core_utils_24_2_1.xml 778B
support_compat_24_2_1.xml 932B
support_media_compat_24_2_1.xml 974B
support_fragment_24_2_1.xml 946B
support_vector_drawable_24_2_1.xml 641B
support_annotations_24_2_1.xml 497B
support_core_ui_24_2_1.xml 939B
animated_vector_drawable_24_2_1.xml 646B
recyclerview_v7_24_2_1.xml 780B
support_v4_24_2_1.xml 420B
hamcrest_core_1_3.xml 526B
appcompat_v7_24_2_1.xml 762B
junit_4_12.xml 477B
.gitignore 105B
local.properties 430B
settings.gradle 16B
build.gradle 521B
共 74 条
- 1
资源评论
qiuyin2015
- 粉丝: 20
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于GPT的AI文档分析、阅读和问答工具.txt
- 《机器人控制系统的设计与Matlab仿真 》仿真程序
- AI-免费物品无损放大工具AI在线免费放大图片工具.txt
- C++基于DPLL算法的SAT的蜂窝数独游戏求解程序,程序设计综合课程设计,包括SAT求解器板块、蜂窝数独转化成cnf公式板块
- 微信小程序恐龙快跑小程序源码.zip
- 黑苹果OC引导-0.9.1
- WinSoft-ComPort-v6.5-for-Delphi-5-11-Downloadly
- Redis 服务等过期策略和内存淘汰策略解析
- debian配置FTP服务
- 基于Matlab和CPLEX的2变量机组组合调度程序(注释完全,可直接运行)(文档加Matlab源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功