栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

使用ListView实现网上订餐首页

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用ListView实现网上订餐首页

本文实例为大家分享了ListView实现网上订餐首页的具体代码,供大家参考,具体内容如下

效果图

布局文件

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SimpleAdapterActivity">

 
 
android:layout_width="match_parent"
 android:layout_height="100dp"
 android:layout_margin="10dp">
 
 
  
  
  
   
   
  


 
 
  

title.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/title_style">

设置福利图标的样式

android:layout_width="match_parent"
android:layout_height="match_parent">

点击listview后跳转的页面布局

android:layout_width="match_parent"
android:layout_height="400dp"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_margin="5dp"
tools:context=".FirstActivity">

android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp">

 
  
  
  />
   




  

java文件

public class SimpleAdapterActivity extends AppCompatActivity {
 private ListView listView;
 private List> data = new ArrayList<>();

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_list_view);
//  ActionBar actionBar = getSupportActionBar();
  if (actionBar!= null){
   actionBar.hide();
  }
  initView();
 }
 public void initView(){
  listView = findViewById(R.id.lv_listview);
  Map map = new HashMap();
  map.put("icon", R.drawable.shop1);
  map.put("name", "蛋糕房");
  map.put("content", "月售996n起送¥35|配送¥5");
  map.put("welfare","进店可获得一个香草冰淇淋");
  map.put("time","配送约2.5小时");
  data.add(map);
  map = new HashMap();
  map.put("icon", R.drawable.shop2);
  map.put("name", "爪哇咖啡.西餐.酒吧");
  map.put("content", "月售11n起送¥20|配送¥7");
  map.put("welfare","进店即可送一杯拿铁咖啡");
  map.put("time","配送约40分钟");
  data.add(map);
  map = new HashMap();
  map.put("icon", R.drawable.shop3);
  map.put("name", "必胜客");
  map.put("content", "月售10n起送¥15|配送¥6");
  map.put("welfare","下单即可获得一个¥5优惠券");
  map.put("time","配送约20分钟");
  data.add(map);
  map = new HashMap();
  map.put("icon", R.drawable.shop4);
  map.put("name", "艾尚夜宵");
  map.put("content", "月售496n起送¥20|配送¥13");
  map.put("welfare","下单即可获得一个¥15优惠券");
  map.put("time","配送约42分钟");
  data.add(map);
  map = new HashMap();
  map.put("icon", R.drawable.shop5);
  map.put("name", "上岛咖啡");
  map.put("content", "月售800n起送¥30|配送¥10");
  map.put("welfare","下单即可获得一个¥30优惠券");
  map.put("time","配送约30分钟");
  data.add(map);

  SimpleAdapter adapter = new SimpleAdapter(this,
    data,R.layout.listview_item,new String[]{"icon","name","content","welfare","time"},
    new int []{R.id.food_image,R.id.food_name,R.id.food_content,R.id.tv_welfare,R.id.tv_time});
  //设置listview的适配器,这里使用SimpleAdapter;
  listView.setAdapter(adapter);
  listView.setonItemClickListener(new AdapterView.onItemClickListener() {
   @Override
   public void onItemClick(AdapterView adapterView, View view, int i, long l) {
    Map map = data.get(i);
    
    Intent intent = new Intent(SimpleAdapterActivity.this,FirstActivity.class);
    startActivity(intent);
   }
  });
 }
}
public class FirstActivity extends AppCompatActivity {
 private Button btnjoin;
 private ListView listView;
 private List> data = new ArrayList<>();

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_first);
  btnjoin = findViewById(R.id.first_btn_join);
  initView();
 }
 public void initView(){
  listView = findViewById(R.id.lv_food);
  Map map = new HashMap();
  map.put("icon", R.drawable.food1);
  map.put("name", "招牌丰收硕果12寸");
  map.put("ingredient", "水果、奶油、面包、鸡蛋");
  map.put("money","¥198");
  map.put("btn","加入购物车");
  data.add(map);
  map = new HashMap();
  map.put("icon", R.drawable.food2);
  map.put("name", "玫瑰花创意蛋糕");
  map.put("ingredient", "玫瑰花、奶油、鸡蛋");
  map.put("money","¥148");
  map.put("btn","加入购物车");
  data.add(map);
  map = new HashMap();
  map.put("icon", R.drawable.food3);
  map.put("name", "布朗熊与可妮");
  map.put("ingredient", "奶油、巧克力、果粒夹层");
  map.put("money","¥98");
  map.put("btn","加入购物车");
  data.add(map);

  SimpleAdapter adapter = new SimpleAdapter(this,
    data,R.layout.activity_first_list,new String[]{"icon","name","ingredient","money","btn"},
    new int []{R.id.first_image,R.id.first_name,R.id.first_ingredient,R.id.tv_money,R.id.first_btn_join});
  //设置listview的适配器,这里使用SimpleAdapter;
  listView.setAdapter(adapter);

 }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/153606.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号