Java 我可以在没有数据库的情况下创建“添加到购物车”功能吗?
我是Android Studio的新手,我想为多个项目创建“添加到购物车”,所以我可以在代码中不使用复选框和单选按钮的数据库来创建它吗Java 我可以在没有数据库的情况下创建“添加到购物车”功能吗?,java,android,Java,Android,我是Android Studio的新手,我想为多个项目创建“添加到购物车”,所以我可以在代码中不使用复选框和单选按钮的数据库来创建它吗 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_weight=
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
<ImageView
android:layout_width="250px"
android:layout_height="250px"
android:src="@drawable/master_baker"
android:layout_marginLeft="150dp" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:layout_marginTop="58dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/img">
<ImageView
android:layout_width="720px"
android:layout_height="720px"
android:src="@drawable/pasta"
android:layout_gravity="center"/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="00dp"
android:layout_below="@+id/img">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price: 15 AED"
android:textSize="25dp"
android:gravity="center_horizontal" />
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Choise:"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#000000"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fadeScrollbars="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="White sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
<RadioButton
android:id="@+id/radio2"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mix sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
<RadioButton
android:id="@+id/radio3"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_marginLeft="70dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Garlic"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark" />
<CheckBox
android:id="@+id/box2"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hotdog"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box3"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chicken"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box4"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tomato"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box5"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brocolli"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box6"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mushroom"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box7"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bellpepper"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box8"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spicy"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box9"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zaater"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box10"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cheese"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<ImageButton
android:layout_marginTop="20dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/cart"
android:background="#00ffffff"
android:layout_gravity="end"
android:id="@+id/cart"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
XML文件:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
<ImageView
android:layout_width="250px"
android:layout_height="250px"
android:src="@drawable/master_baker"
android:layout_marginLeft="150dp" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:layout_marginTop="58dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/img">
<ImageView
android:layout_width="720px"
android:layout_height="720px"
android:src="@drawable/pasta"
android:layout_gravity="center"/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="00dp"
android:layout_below="@+id/img">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price: 15 AED"
android:textSize="25dp"
android:gravity="center_horizontal" />
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Choise:"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#000000"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fadeScrollbars="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="White sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
<RadioButton
android:id="@+id/radio2"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mix sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
<RadioButton
android:id="@+id/radio3"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_marginLeft="70dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Garlic"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark" />
<CheckBox
android:id="@+id/box2"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hotdog"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box3"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chicken"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box4"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tomato"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box5"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brocolli"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box6"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mushroom"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box7"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bellpepper"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box8"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spicy"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box9"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zaater"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box10"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cheese"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<ImageButton
android:layout_marginTop="20dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/cart"
android:background="#00ffffff"
android:layout_gravity="end"
android:id="@+id/cart"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
是的,您可以使用共享首选项。
创建arraylist并添加项目,然后将其存储到首选项中 。。。没有数据库??!!对我来说,这听起来像科幻小说。这比小说还奇怪,而且表明之前没有任何研究。移动应用程序中的数据库还是后端?取决于您正在构建的内容,添加到购物车有点宽泛…在某种程度上,这个看起来很相似。。。用户名甚至刚刚更改。这不会向互联网上的其他用户显示哪些产品在商店里,哪些已经售罄。甚至对店主也没有。这将是一个本地保存的。。。伪造的
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
<ImageView
android:layout_width="250px"
android:layout_height="250px"
android:src="@drawable/master_baker"
android:layout_marginLeft="150dp" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:layout_marginTop="58dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/img">
<ImageView
android:layout_width="720px"
android:layout_height="720px"
android:src="@drawable/pasta"
android:layout_gravity="center"/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="00dp"
android:layout_below="@+id/img">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price: 15 AED"
android:textSize="25dp"
android:gravity="center_horizontal" />
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Choise:"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#000000"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fadeScrollbars="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="White sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
<RadioButton
android:id="@+id/radio2"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mix sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
<RadioButton
android:id="@+id/radio3"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red sauce"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_marginLeft="70dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Garlic"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark" />
<CheckBox
android:id="@+id/box2"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hotdog"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box3"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chicken"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box4"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tomato"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box5"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brocolli"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box6"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mushroom"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box7"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bellpepper"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box8"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spicy"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box9"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zaater"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<CheckBox
android:id="@+id/box10"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cheese"
android:textSize="20dp"
android:buttonTint="@color/colorPrimaryDark"
android:checked="false"/>
<ImageButton
android:layout_marginTop="20dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/cart"
android:background="#00ffffff"
android:layout_gravity="end"
android:id="@+id/cart"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>