gpt4 book ai didi

android - 如何临时保存数据?比如安卓应用中的购物车

转载 作者:行者123 更新时间:2023-11-30 01:03:01 29 4
gpt4 key购买 nike

我是初学者 android 开发者。我有关于临时保存购物车数据的问题。这是一个定制衬衫应用程序。客人应选择衣领、袖口等。我使用 ListView 显示客人选择的这些选定项目和选项。

public class Cart_item_list {
private static int cart_itemimage;
private static String cart_itemname;
private static String cart_itemprice;
private static String cart_collar;
private static String cart_cuffs;
private static String cart_placket;
private static String cart_pocket;
private static String cart_fit;
private static String cart_initial;

public static int getCart_itemimage() {
return cart_itemimage;
}

public static void setCart_itemimage(int cart_itemimage) {
Cart_item_list.cart_itemimage = cart_itemimage;
}

public static String getCart_itemname() {
return cart_itemname;
}

public static void setCart_itemname(String cart_itemname) {
Cart_item_list.cart_itemname = cart_itemname;
}

public static String getCart_itemprice() {
return cart_itemprice;
}

public static void setCart_itemprice(String cart_itemprice) {
Cart_item_list.cart_itemprice = cart_itemprice;
}

public static String getCart_collar() {
return cart_collar;
}

public static void setCart_collar(String cart_collar) {
Cart_item_list.cart_collar = cart_collar;
}

public static String getCart_cuffs() {
return cart_cuffs;
}

public static void setCart_cuffs(String cart_cuffs) {
Cart_item_list.cart_cuffs = cart_cuffs;
}

public static String getCart_placket() {
return cart_placket;
}

public static void setCart_placket(String cart_placket) {
Cart_item_list.cart_placket = cart_placket;
}

public static String getCart_pocket() {
return cart_pocket;
}

public static void setCart_pocket(String cart_pocket) {
Cart_item_list.cart_pocket = cart_pocket;
}

public static String getCart_fit() {
return cart_fit;
}

public static void setCart_fit(String cart_fit) {
Cart_item_list.cart_fit = cart_fit;
}

public static String getCart_initial() {
return cart_initial;
}

public static void setCart_initial(String cart_initial) {
Cart_item_list.cart_initial = cart_initial;
}


public Cart_item_list(int cart_itemimage, String cart_itemname, String cart_itemprice, String cart_collar, String cart_cuffs, String cart_placket, String cart_pocket, String cart_fit, String cart_initial) {
this.cart_itemimage = cart_itemimage;
this.cart_itemname = cart_itemname;
this.cart_itemprice = cart_itemprice;
this.cart_collar = cart_collar;
this.cart_cuffs = cart_cuffs;
this.cart_placket = cart_placket;
this.cart_pocket = cart_pocket;
this.cart_fit = cart_fit;
this.cart_initial = cart_initial;

}

这是 ListView 适配器的项目列表。

package com.example.yeong.shifendingzhi;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class Cart_item_adapter extends BaseAdapter {
Context context;
ArrayList<Cart_item_list> cart_item_listArrayList;


public Cart_item_adapter(Context context, ArrayList<Cart_item_list> cart_item_listArrayList) {
this.context = context;
this.cart_item_listArrayList = cart_item_listArrayList;
}


@Override
public int getCount() {
return cart_item_listArrayList.size();
}

@Override
public Object getItem(int i) {
return cart_item_listArrayList.get(i);
}

@Override
public long getItemId(int i) {
return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = LayoutInflater.from(context).inflate(R.layout.cart_listview, null);
ImageView selected_item_image = (ImageView) view.findViewById(R.id.selected_item_image);
TextView selected_cart_name = (TextView) view.findViewById(R.id.selected_cart_name);
TextView selected_cart_cuffs = (TextView) view.findViewById(R.id.selected_cart_cuffs);
TextView selected_cart_initial = (TextView) view.findViewById(R.id.selected_cart_initial);
TextView selected_cart_placket = (TextView) view.findViewById(R.id.selected_cart_placket);
TextView selected_cart_fit = (TextView) view.findViewById(R.id.selected_cart_fit);
TextView selected_cart_pocket = (TextView) view.findViewById(R.id.selected_cart_pocket);
TextView selected_cart_price = (TextView) view.findViewById(R.id.selected_cart_price);
TextView selected_cart_collar = (TextView) view.findViewById(R.id.selected_cart_collar);

selected_cart_name.setText(cart_item_listArrayList.get(i).getCart_itemname());
selected_cart_cuffs.setText(cart_item_listArrayList.get(i).getCart_cuffs());
selected_cart_initial.setText(cart_item_listArrayList.get(i).getCart_initial());
selected_cart_placket.setText(cart_item_listArrayList.get(i).getCart_placket());
selected_cart_fit.setText(cart_item_listArrayList.get(i).getCart_fit());
selected_cart_pocket.setText(cart_item_listArrayList.get(i).getCart_pocket());
selected_cart_price.setText(cart_item_listArrayList.get(i).getCart_itemprice());
selected_cart_collar.setText(cart_item_listArrayList.get(i).getCart_collar());
selected_item_image.setImageResource(cart_item_listArrayList.get(i).getCart_itemimage());
return view;
}

这是 ListView 适配器我尝试创建全局变量 arraylist,并进行了很多搜索,但都失败了,单例,使用应用程序。你能帮我为 ListView 制作全局数组列表吗?它帮助我临时保存数据并在另一项 Activity 中更改 arraylist 数据。谢谢。

最佳答案

我推荐来自 https://github.com/pilgr/Paper 的论文库

它易于配置,无需设置任何 sql 类型的连接,就像在本地写入文本文件一样。我用过它,它很结实。我主要用它来存储登录 Activity 页面中记住我的用户名和密码:

 if(ckbRemember.isChecked())
{
Paper.book().write(Common.USER_KEY,edtUsername.getText().toString());
Paper.book().write(Common.PWD_KEY,edtPassword.getText().toString());
}

当您想随时从任何 Activity 中清除数据时,就像:

Paper.book().destroy();

关于android - 如何临时保存数据?比如安卓应用中的购物车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39206784/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com