从零开始制作点餐Android app(一)

您所在的位置:网站首页 psv错误代码c092506 从零开始制作点餐Android app(一)

从零开始制作点餐Android app(一)

#从零开始制作点餐Android app(一)| 来源: 网络整理| 查看: 265

1.2020/7/19开始 做个记录,学习Android 开发环境: jdk:1.8 Android studio 4.0 一、首先,建立项目工程(按照下图操作)

二、建立好之后,会默认打开我们所创建的工程,我们按照如下操作 1、导入所需的jar文件 2、编写颜色资源文件

3、创建工程项目结构 在这里插入图片描述 三、首页设计 一)标题栏设计 1、新建标题布局文件

a:编写内容: title_bar.xml

2、创建点击事件选择器 iv_back_selector.xml

activity_main.xml

style.xml

@color/colorPrimary @color/colorPrimaryDark @color/colorAccent

自此首页标题栏布局完成。

二)内容页设计

activity_main.xml

mainactivity.java

package com.example.orderproject.activity; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import com.example.orderproject.R; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private TextView tvTitle; private ListView ivshopList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { tvTitle=findViewById(R.id.tv_title); ivshopList=findViewById(R.id.iv_shop_list); List list=new ArrayList(); for (int i=0;i public ShopListView(Context context) { super(context); } public ShopListView(Context context, AttributeSet attrs) { super(context, attrs); } public ShopListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightSpec=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >>2,MeasureSpec.AT_MOST); //VIEW的大小采用30位进行存储,那么我们应该给他30位的最大值,Int的最大值是32位 super.onMeasure(widthMeasureSpec,heightSpec); } }

效果图: 最终效果图 自此内容页布局结束

三)内容填充 创建工具文件。用于连接服务器并获取数据 装插件:gsonformat gsonformat使用参考教程 装完之后要重新打开Android studio之后才会生效。 试下我们的接口地址: 复制接口全部内容。

然后再在我们的类下面去使用gsonformat。把我们上面的内容复制进去,就可以生成我们所需要的东西了。

这就是我们的生成的文件类了,有了这个东西就不需要自己去打对应的json的代码了。

package com.example.orderproject.bean; import java.util.List; public class ShopBean { /** * id : 1 * shopName : 蛋糕房 * saleNum : 996 * offerPrice : 100 * distributionCost : 5 * welfare : 进店可获得一个香草冰淇淋 * time : 配送约2-5小时 * shopPic : http://192.168.31.135:3000/order/img/shop/shop1.png * shopNotice : 公告:下单后2-5小时送达!请耐心等候 * foodList : [{"foodId":"1","foodName":"招牌丰收硕果12寸","taste":"水果、奶油、面包、鸡蛋","saleNum":"50","price":198,"count":0,"foodPic":"http://192.168.31.135:3000/order/img/food/food1.png"},{"foodId":"2","foodName":"玫瑰花创意蛋糕","taste":"玫瑰花、奶油、鸡蛋","saleNum":"100","price":148,"count":0,"foodPic":"http://192.168.31.135:3000/order/img/food/food2.png"},{"foodId":"3","foodName":"布朗熊与可妮","taste":"奶油、巧克力、果粒夹层","saleNum":"80","price":90,"count":0,"foodPic":"http://192.168.31.135:3000/order/img/food/food3.png"}] */ private int id; private String shopName; private int saleNum; private int offerPrice; private int distributionCost; private String welfare; private String time; private String shopPic; private String shopNotice; private List foodList; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getShopName() { return shopName; } public void setShopName(String shopName) { this.shopName = shopName; } public int getSaleNum() { return saleNum; } public void setSaleNum(int saleNum) { this.saleNum = saleNum; } public int getOfferPrice() { return offerPrice; } public void setOfferPrice(int offerPrice) { this.offerPrice = offerPrice; } public int getDistributionCost() { return distributionCost; } public void setDistributionCost(int distributionCost) { this.distributionCost = distributionCost; } public String getWelfare() { return welfare; } public void setWelfare(String welfare) { this.welfare = welfare; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getShopPic() { return shopPic; } public void setShopPic(String shopPic) { this.shopPic = shopPic; } public String getShopNotice() { return shopNotice; } public void setShopNotice(String shopNotice) { this.shopNotice = shopNotice; } public List getFoodList() { return foodList; } public void setFoodList(List foodList) { this.foodList = foodList; } public static class FoodListBean { /** * foodId : 1 * foodName : 招牌丰收硕果12寸 * taste : 水果、奶油、面包、鸡蛋 * saleNum : 50 * price : 198 * count : 0 * foodPic : http://192.168.31.135:3000/order/img/food/food1.png */ private String foodId; private String foodName; private String taste; private String saleNum; private int price; private int count; private String foodPic; public String getFoodId() { return foodId; } public void setFoodId(String foodId) { this.foodId = foodId; } public String getFoodName() { return foodName; } public void setFoodName(String foodName) { this.foodName = foodName; } public String getTaste() { return taste; } public void setTaste(String taste) { this.taste = taste; } public String getSaleNum() { return saleNum; } public void setSaleNum(String saleNum) { this.saleNum = saleNum; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public String getFoodPic() { return foodPic; } public void setFoodPic(String foodPic) { this.foodPic = foodPic; } } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3