欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用ListView實現(xiàn)網(wǎng)上訂餐首頁

 更新時間:2021年01月02日 13:01:21   作者:" 霎那凝眸,三生不忘゛  
這篇文章主要為大家詳細介紹了使用ListView實現(xiàn)網(wǎng)上訂餐首頁,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了ListView實現(xiàn)網(wǎng)上訂餐首頁的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

布局文件

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SimpleAdapterActivity">
<include layout="@layout/title"/>
 <ImageView
  android:layout_width="match_parent"
  android:layout_height="200dp"
  android:src="@drawable/chinaweidao"/>
 <ListView
  android:dividerHeight="5dp"
  android:id="@+id/lv_listview"
  android:layout_marginTop="10dp"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />
</LinearLayout>
android:layout_width="match_parent"
 android:layout_height="100dp"
 android:layout_margin="10dp">
 <ImageView
  android:id="@+id/food_image"
  android:layout_width="80dp"
  android:layout_height="80dp"/>
 <LinearLayout
  android:orientation="vertical"
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="3">
  <TextView
   android:id="@+id/food_name"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:text="標題"
   android:textSize="16sp"
   android:gravity="center_vertical"
   android:textColor="#000000"/>
  <TextView
   android:id="@+id/food_content"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:text="內(nèi)容"
   android:textSize="12sp"
   android:gravity="center_vertical"/>
  <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   <include layout="@layout/welfarestyle"/>
   <TextView
    android:id="@+id/tv_welfare"
    android:layout_marginLeft="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"/>
  </LinearLayout>


 </LinearLayout>
 <LinearLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1">
  <TextView
   android:id="@+id/tv_time"
   android:layout_width="wrap_content"
   android:layout_height="match_parent"
   android:text="時間"
   android:textSize="10sp"
   android:gravity="center_vertical"/>

</LinearLayout>

title.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/title_style">
<TextView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:text="店鋪"
  android:textColor="#ffffff"
  android:textSize="20sp"
  android:textStyle="bold"
  android:gravity="center"/>

設(shè)置福利圖標的樣式

android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
  android:layout_marginLeft="10dp"
  android:layout_width="30dp"
  android:layout_height="20dp"
  android:text="福利"
  android:textColor="#fff"
  android:background="@drawable/welfare"/>

點擊listview后跳轉(zhuǎn)的頁面布局

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">
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="菜單"
  android:layout_margin="10dp"
  android:textSize="20dp"
  android:textColor="#000000"/>
<ListView
  android:layout_margin="8dp"
  android:id="@+id/lv_food"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp">
<ImageView
  android:id="@+id/first_image"
  android:layout_width="80dp"
  android:layout_height="80dp"/>
 <LinearLayout
  android:orientation="vertical"
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="3">
  <TextView
   android:id="@+id/first_name"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:text="標題"
   android:textSize="16sp"
   android:gravity="center_vertical"
   android:textColor="#000000"/>
  <TextView
   android:id="@+id/first_ingredient"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:text="內(nèi)容"
   android:textSize="12sp"
   android:textColor="#000000"
   android:gravity="center_vertical"/>
  <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">/>
   <TextView
    android:id="@+id/tv_money"
    android:layout_marginLeft="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:text="價格"/>
</LinearLayout>

</LinearLayout>
<LinearLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1.5">
  <Button
   android:id="@+id/first_btn_join"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="加入購物車"
   android:background="@android:drawable/btn_default"
   android:layout_gravity="center_vertical" />

</LinearLayout>
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp">
<ImageView
  android:id="@+id/first_image"
  android:layout_width="80dp"
  android:layout_height="80dp"/>
 <LinearLayout
  android:orientation="vertical"
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="3">
  <TextView
   android:id="@+id/first_name"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:text="標題"
   android:textSize="16sp"
   android:gravity="center_vertical"
   android:textColor="#000000"/>
  <TextView
   android:id="@+id/first_ingredient"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:text="內(nèi)容"
   android:textSize="12sp"
   android:textColor="#000000"
   android:gravity="center_vertical"/>
  <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">/>
   <TextView
    android:id="@+id/tv_money"
    android:layout_marginLeft="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:text="價格"/>
</LinearLayout>

</LinearLayout>
<LinearLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1.5">
  <Button
   android:id="@+id/first_btn_join"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="加入購物車"
   android:background="@android:drawable/btn_default"
   android:layout_gravity="center_vertical" />

</LinearLayout>

java文件

public class SimpleAdapterActivity extends AppCompatActivity {
 private ListView listView;
 private List<Map<String,Object>> 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<String, Object> map = new HashMap<String, Object>();
  map.put("icon", R.drawable.shop1);
  map.put("name", "蛋糕房");
  map.put("content", "月售996\n起送¥35|配送¥5");
  map.put("welfare","進店可獲得一個香草冰淇淋");
  map.put("time","配送約2.5小時");
  data.add(map);
  map = new HashMap<String, Object>();
  map.put("icon", R.drawable.shop2);
  map.put("name", "爪哇咖啡.西餐.酒吧");
  map.put("content", "月售11\n起送¥20|配送¥7");
  map.put("welfare","進店即可送一杯拿鐵咖啡");
  map.put("time","配送約40分鐘");
  data.add(map);
  map = new HashMap<String, Object>();
  map.put("icon", R.drawable.shop3);
  map.put("name", "必勝客");
  map.put("content", "月售10\n起送¥15|配送¥6");
  map.put("welfare","下單即可獲得一個¥5優(yōu)惠券");
  map.put("time","配送約20分鐘");
  data.add(map);
  map = new HashMap<String, Object>();
  map.put("icon", R.drawable.shop4);
  map.put("name", "艾尚夜宵");
  map.put("content", "月售496\n起送¥20|配送¥13");
  map.put("welfare","下單即可獲得一個¥15優(yōu)惠券");
  map.put("time","配送約42分鐘");
  data.add(map);
  map = new HashMap<String, Object>();
  map.put("icon", R.drawable.shop5);
  map.put("name", "上島咖啡");
  map.put("content", "月售800\n起送¥30|配送¥10");
  map.put("welfare","下單即可獲得一個¥30優(yōu)惠券");
  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});
  //設(shè)置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);
    /* Toast.makeText(SimpleAdapterActivity.this, "你點擊了"+map.get("name")+map.get("content"), Toast.LENGTH_SHORT).show();*/
    Intent intent = new Intent(SimpleAdapterActivity.this,FirstActivity.class);
    startActivity(intent);
   }
  });
 }
}
public class FirstActivity extends AppCompatActivity {
 private Button btnjoin;
 private ListView listView;
 private List<Map<String,Object>> 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<String, Object> map = new HashMap<String, Object>();
  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<String, Object>();
  map.put("icon", R.drawable.food2);
  map.put("name", "玫瑰花創(chuàng)意蛋糕");
  map.put("ingredient", "玫瑰花、奶油、雞蛋");
  map.put("money","¥148");
  map.put("btn","加入購物車");
  data.add(map);
  map = new HashMap<String, Object>();
  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});
  //設(shè)置listview的適配器,這里使用SimpleAdapter;
  listView.setAdapter(adapter);

 }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android中AsyncTask與handler用法實例分析

    Android中AsyncTask與handler用法實例分析

    這篇文章主要介紹了Android中AsyncTask與handler用法,以實例形式較為詳細的分析了Android中AsyncTask與handler的功能、用法與相關(guān)注意事項,并附帶完整實例源碼供讀者下載,需要的朋友可以參考下
    2015-10-10
  • Android應(yīng)用開發(fā)中CardView的初步使用指南

    Android應(yīng)用開發(fā)中CardView的初步使用指南

    這篇文章主要介紹了Android應(yīng)用開發(fā)中CardView的初步使用指南,CardView主要處理一些卡片型的視圖布局,需要的朋友可以參考下
    2016-02-02
  • Android實現(xiàn)底部圖片選擇Dialog

    Android實現(xiàn)底部圖片選擇Dialog

    這篇文章主要為大家詳細介紹了Android實現(xiàn)底部圖片選擇Dialog,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • android編程實現(xiàn)設(shè)置、打開wifi熱點共享供他人連接的方法

    android編程實現(xiàn)設(shè)置、打開wifi熱點共享供他人連接的方法

    這篇文章主要介紹了android編程實現(xiàn)設(shè)置、打開wifi熱點共享供他人連接的方法,涉及Android創(chuàng)建WiFi及設(shè)置共享的相關(guān)實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-11-11
  • Flutter 容器盒子模型的使用示例

    Flutter 容器盒子模型的使用示例

    在網(wǎng)頁開發(fā)中,有盒子模型,號稱統(tǒng)一三端的 Flutter 也不例外,而且和 HTML 的盒子模型幾乎是一樣的,本篇文章通過簡單的例子說明一下 Flutter 的盒子模型,方便以后再做界面時可以更好的理解布局。
    2021-05-05
  • 系統(tǒng)應(yīng)用根據(jù)Uri授予權(quán)限方法詳解

    系統(tǒng)應(yīng)用根據(jù)Uri授予權(quán)限方法詳解

    這篇文章主要為大家介紹了系統(tǒng)應(yīng)用根據(jù)Uri授予權(quán)限方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • Android Jetpack組件中LiveData的優(yōu)劣

    Android Jetpack組件中LiveData的優(yōu)劣

    LiveData是Jetpack組件的一部分,更多的時候是搭配ViewModel來使用,相對于Observable,LiveData的最大優(yōu)勢是其具有生命感知的,換句話說,LiveData可以保證只有在組件(?Activity、Fragment、Service)處于活動生命周期狀態(tài)的時候才會更新數(shù)據(jù)
    2023-04-04
  • android Matrix實現(xiàn)圖片隨意放大縮小或拖動

    android Matrix實現(xiàn)圖片隨意放大縮小或拖動

    這篇文章主要為大家詳細介紹了android Matrix實現(xiàn)圖片隨意放大縮小或拖動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android Studio一直處于Building的兩種解決方法

    Android Studio一直處于Building的兩種解決方法

    很多朋友都遇到過打開別人的項目一直處于Building‘XXX’Gradle project info的情況。下面小編給大家?guī)砹薃ndroid Studio一直處于Building的解決方法,感興趣的朋友一起看看吧
    2018-08-08
  • Android中捕獲全局異常實現(xiàn)代碼

    Android中捕獲全局異常實現(xiàn)代碼

    這篇文章主要介紹了Android中捕獲全局異常實現(xiàn)代碼,本文給出了2種方法,以及對應(yīng)實現(xiàn)代碼,需要的朋友可以參考下
    2015-04-04

最新評論