安卓商城购物车布局案例

安卓商城购物车案例

写的很垃圾也是初学呢,望多包容
大概长这样:
在这里插入图片描述

activity_main.xml布局文件

<?xml version="1.0" encoding="utf-8"?> 
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    app:layout_constraintTop_toTopOf="parent" 
   > 
 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:orientation="vertical"> 
        <TextView 
            app:layout_constraintTop_toTopOf="parent" 
            android:layout_width="match_parent" 
            android:layout_height="40dp" 
            android:textSize="30sp" 
            android:text="           -------欢迎光临-------" /> 
 
    <ListView 
        android:id="@+id/listview" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"/> 
    <Button 
        android:layout_width="match_parent" 
        android:layout_height="70dp" 
        android:text="选好了" 
        android:textSize="30sp"/> 
</LinearLayout> 
</androidx.constraintlayout.widget.ConstraintLayout> 

Ls_tmist_itemxl.xml板模板件

<?xml version="1.0" encoding="utf-8"?> 
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
 
    > 
 
    <CheckBox 
        android:id="@+id/checkBox" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
 
       /> 
 
    <ImageView 
        android:id="@+id/image" 
        android:layout_width="110dp" 
        android:layout_height="110dp" 
        android:padding="5dp" 
        app:srcCompat="@drawable/dish_01" /> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
 
    <TextView 
        android:id="@+id/name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:padding="5dp" 
        android:textColor="#000fff" 
        android:textSize="30sp" /> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
        android:id="@+id/money" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:textColor="#D52F23" 
        android:textSize="30sp" 
        android:textStyle="bold" /> 
    <TextView 
 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
       android:text="元/份" 
        android:textStyle="bold" /> 
 
</LinearLayout> 
</LinearLayout> 
</LinearLayout> 

Jvava码代码

package com.example.menutest; 
 
import androidx.appcompat.app.AppCompatActivity; 
 
import android.app.LauncherActivity; 
import android.os.Bundle; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
 
import java.util.ArrayList; 
import java.util.HashMap; 
 
public class MainActivity extends AppCompatActivity { 
    ArrayList<HashMap<Sting,Object>>lisItems=null; 
    HashMap<String,Object>map=null; 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        ListView mylistview=(ListView)findViewById(R.id.listview); 
        ArrayList<HashMap<String, Object>> listItems = new ArrayList<HashMap<String, 
Object>>(); 
        int[] 
userImg={R.drawable.dish_01,R.drawable.dish_02,R.drawable.dish_03,R.drawable.dish_04,R.d
rawable.dish_05, 
                R.drawable.dish_06,R.drawable.dish_07,R.drawable.dish_08}; 
        String[] menuName=getResources().getStringArray(R.array.menuName); 
        String[] money=getResources().getStringArray(R.array.money); 
        for(int i=0;i<money.length;i++){ 
            map=new HashMap<String,Object>(); 
            map.put("img",userImg[i]); 
            map.put("name",menuName[i]); 
            map.put("money",money[i]); 
            listItems.add(map); 
        } 
        //创建并实例化SimpleAdapter 
        SimpleAdapter  adapter=new SimpleAdapter(this,listItems,R.layout.list_item,new 
String[]{"img","name","money"}, 
                new int[]{R.id.image,R.id.name,R.id.money}); 
        mylistview.setAdapter(adapter); 
       // mylistview.setOnItemClickListener(); 
 
    } 
} 

emmmmm,这只是学校的一个小作业,记录一下,有更好的方法欢迎留言交流,也让我学习学习,哈哈哈哈

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值