Ⅰ android中怎樣實現購物車右上角的數字顯示
我給你個類似的例子,自己改改就可以
發我個郵箱,或加我QQ 891847667
Ⅱ 關於android的購物車功能是怎麼實現的
主要代碼如下: 是主要代碼,
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;
@
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 = 0; i < 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 = 0; i < 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 = 0; i < 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;
}
}
Ⅲ 如何實現購物車功能 android 博客
你先要把這個界面布局給弄好,圖片、文字、價格等都是從伺服器獲取的,然後用baseadapter適配器填充到listview中,最後進行相應的控制項的事件處理就好了。
Ⅳ Android 實現美團,餓了么購物車效果
對兩個按鈕的背復景進行改變button、button2的選中制和為選擇狀態.beijing1).drawable.setBackgroundResource(R,讓後再button1和button2的點擊事件中,分別為button1的選中和為選擇狀態;上面是改變按鈕背景的代碼可以做兩組圖片
Ⅳ Java 如何實現類似購物車功能
給你介紹三種可以實現購物車功能的方法:
1.用cookie實現購物車;
2.用session實現購物車;
3.用cookie和資料庫(購物車信息持久化)實現購物車;
=======================================================
分析一下這三種方法的優缺點:
1.單純有cookie實現購物車,這樣的購物車不是很理想,設想一下,如果客戶端的瀏覽器把cookie給禁用了,這種方法就會在這里流產...
2.session中保存購物車的信息,這個只是在一個會話中可用,如果用戶沒有登錄,或者說登錄了以後,添加購物車,在關閉瀏覽器或者登出後,之前所添加的購物車通通都流產啦...
3.用cookie和資料庫(購物車信息持久化)實現購物車;
主要的流程:
A.用戶登錄前的數據流:用戶在沒有登錄系統的時候,對喜歡的商品進行添加購物車,那麼這個時候,我們可以把購物車信息保存
到cookie中,這里會涉及到cookie的添加,修改操作;也即如果之前在cookie中不存對應的cookie,則就對cookie進行添加操作。
如果在cookie中存在對應的cookie,那麼,這時候,就要對cookie進行修改操作了(這里涉及到用戶對同一個商品進行多次添加購物車的情況)。
B.用戶登錄後的數據流:用戶在登錄後,系統首先做的第一件事就是去獲取對應的cookies,如果存在相關的購物車cookies,那麼就對該購物車
信息進行相應用戶User的持久化操作,要麼添加,要麼修改。(添加操作:該用戶所對應的購物車如果沒有相應的信息進行添加操作;修改操作:類似的,
如果存在對應用戶的購物車信息,就進行修改操作)。用戶登錄後,也可以進行購物車的添加操作,不過,這里不是添加到cookie中,而是直接持久化到資料庫中。
Ⅵ java中購物車的功能怎麼實現
session+cookie。先從cookie里讀取上次的購物清單到session,本次添加的購物清單也將加入session。
Ⅶ 當當網購物車功能如何用java實現
放進購物車的東西,添加到List,然後用Sesion......發送、接收
Ⅷ android 添加到購物車怎麼實現
Android購物車的實現可以使用資料庫的方法,把加入的物品信息插入到資料庫中,點擊查看購物車時,查詢資料庫購物車的信息即可
Ⅸ 關於android的購物車功能是怎麼實現的
1.頁面布局根布局用相對布局,其中有兩個子布局,有一個子布局回null_layout來放空數據時需要展答示的頁面visibility設為gone,另一個子布局就是你有數據顯示的樣子,請求伺服器購物車或者本地資料庫查詢時,若無則將null_layout的visibility設為visible,有則又設成gone就行2.這個邏輯不對啊,商品列表點一下不是應該去商品詳情,然後用戶自己再選擇加入購物車並選數量么,怎麼就直接加入購物車了...一般做購物車都會做本地資料庫,加入購物車按鈕被點擊就向本地插入一條數據到資料庫並發請求告訴後台也同步,商品數量是用戶選的,價格是自己算的(單價*數量),購物車顯示時查這個表就行
Ⅹ android仿淘寶購物車 如何實現
這個問題可以使用代理解決,當你能理解代理業就可以搞定了。
具體代碼沒有,你可以去網上找代理代碼,特別類似蘋果代碼的那種代理。