关于android的购物车功能是怎么实现的

关于android的购物车功能是怎么实现的,第1张

主要代码如下: 是主要代码,

actvity中的代码:

public class ShoppingCartActivity extends BaseActivity {

private List<Test>data

private ListView mListView

private ShoppingCartAdapter adapter

private RelativeLayout rlRefresh

private TextView tvRefresh

private ProgressBar barRefresh

private LinearLayout clear

private CheckBox checkBox_select_all

private CheckBox checkBox_add

private TextView integral_sum

private int sum = 0

private int[] sumIntegral

private Context context

@Override

protected void onCreate(Bundle bundle) {

// TODO Auto-generated method stub

super.onCreate(bundle)

setContentView(R.layout.activity_shopping_cart)

initView()

}

private void initView() {

context = this

showpage = 1

isPermitFlag = true

data = new ArrayList<Test>()

// 测试数据

data.add(new Test("id", "color", "type", "100"))

data.add(new Test("id", "color", "type", "200"))

data.add(new Test("id", "color", "type", "300"))

adapter = new ShoppingCartAdapter(context, handler, data)

sumIntegral = new int[data.size() + 1]

checkBox_add = (CheckBox) findViewById(R.id.checkbox_add)

integral_sum = (TextView) findViewById(R.id.integral_sum)

clear = (LinearLayout) findViewById(R.id.clear)

clear.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

data.clear()

adapter.notifyDataSetChanged()

integral_sum.setText(0 + "")

checkBox_select_all.setChecked(false)

checkBox_add.setClickable(false)

}

})

cted.entrySet().iterator()

for (int i = 0i <data.size()i++) {

int num = data.get(i).getNum()

int integral = Integer.valueOf(data.get(i).getIntegral())

nums.add(num)

})

<CheckBox

android:layout_width="12dp"

android:layout_height="12dp"

android:background="@drawable/clear" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="5dp"

android:text="清空购物车"

android:textColor="#b61d1d"

android:textSize="@dimen/small_size" />

</LinearLayout>

</LinearLayout>

<CheckBox

android:id="@+id/checkbox_add"

style="@style/CustomCheckboxTheme2"

android:layout_width="wrap_content"

android:clickable="false"

android:layout_height="wrap_content" />

Adaper中的代码:

public class ShoppingCartAdapter extends BaseAdapter {

private Context context

private List<Test>loans

private LayoutInflater inflater

private static HashMap<Integer, Boolean>isSelected

private static HashMap<Integer, Integer>numbers

private Handler handler

int num// 商品数量

static class ViewHolder { // 自定义控件集合

public CheckBox ck_select

public ImageView pic_goods

public TextView id_goods

public TextView color_goods

public TextView type_goods

public TextView integral_goods

public AddMinusWidget add_minus

public LinearLayout layout

public TextView number

public Button minus

public Button plus

}

/**

* 实例化Adapter

*

* @param context

* @param data

*/

public ShoppingCartAdapter(Context context, Handler handler, List<Test>data) {

this.context = context

this.inflater = LayoutInflater.from(context)

this.loans = data

this.handler = handler

isSelected = new HashMap<Integer, Boolean>()

numbers = new HashMap<Integer, Integer>()

initDate()

}

private void initDate() {

for (int i = 0i <loans.size()i++) {

getIsSelected().put(i, false)

getNumbers().put(i, 1)

}

}

@Override

public int getCount() {

return loans.size()

}

@Override

public Object getItem(int position) {

return loans.get(position)

}

@Override

public long getItemId(int position) {

return position

}

/**

* 计算选中商品的积分

*

* @return 返回需要付费的总积分

*/

private float getTotalPrice() {

Test bean = null

float totalPrice = 0

for (int i = 0i <loans.size()i++) {

bean = loans.get(i)

if (ShoppingCartAdapter.getIsSelected().get(i)) {

totalPrice += bean.getNum()

* Integer.valueOf(bean.getIntegral())

}

}

return totalPrice

}

public static HashMap<Integer, Boolean>getIsSelected() {

return isSelected

}

public static void setIsSelected(HashMap<Integer, Boolean>isSelected) {

ShoppingCartAdapter.isSelected = isSelected

}

public static HashMap<Integer, Integer>getNumbers() {

return numbers

}

public static void setNumbers(HashMap<Integer, Integer>numbers) {

ShoppingCartAdapter.numbers = numbers

}

实体类

package com.autoserve.net33.model

public class Test {

@Override

public String toString() {

return "test [id=" + id + ", color=" + color

+ ", type=" + type + ", integral=" + integral + "]"

}

public String getId() {

return id

}

public void setId(String id) {

this.id = id

}

public String getColor() {

return color

}

public void setColor(String color) {

this.color = color

}

public String getType() {

return type

}

public void setType(String type) {

this.type = type

}

public String getIntegral() {

return integral

}

public void setIntegral(String integral) {

this.integral = integral

}

private String id

private String color

private String type

private String integral

private int num//商品数量

private int sumIntegral

private boolean isChoosed //商品是否在购物车中被选中

public Test(String id, String color, String type, String integral) {

super()

this.id = id

this.color = color

this.type = type

this.integral = integral

}

public Test() {

super()

}

public int getNum() {

return num

}

public void setNum(int num) {

this.num = num

}

public int getSumIntegral() {

return sumIntegral

}

public void setSumIntegral(int sumIntegral) {

this.sumIntegral = sumIntegral

}

public boolean isChoosed() {

return isChoosed

}

public void setChoosed(boolean isChoosed) {

this.isChoosed = isChoosed

}

}

第一步:

获取asset文件

第二步(有时可跳过这层)s:

中间转化层,转化为中间文件类型,如图片就是bitmap

第三步:

将中间文件存入本地sd卡,或直接将asset文件流存入本地SdCard

//我没有用jquery,我这里没有jquery的插件直接用js写的,你自己改成jquery就行。 把文字替换成图片就行。

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">

*{margin:0pxpadding:0}

div #div1{

width:300px

height : 300px

float : left

background : red

}

div #div2{

width:300px

height : 300px

float : left

background : green

}

</style>

<script type="text/javascript">

function oc(obj){

var div2 = document.getElementById("div2")

div2.innerHTML = obj.innerHTML

}

</script>

</head>

<body>

<div>

<div id="div1">

<li>

<ul><a onclick='oc(this)' href="#">yuxiangrousi</a></ul>

<ul><a onclick='oc(this)' href="#" >yuxiangqiezi</a></ul>

<ul><a onclick='oc(this)' href="#">tangcuyu</a></ul>

</li>

</div>

<div id='div2'>

</div>

<div>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11411319.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存