zoukankan      html  css  js  c++  java
  • 第一阶段冲刺六

    完成任务:系统管理员使用界面

    一、样图

    二、代码

    package com.example.hotel.Activity.Manager;

    import androidx.appcompat.app.AppCompatActivity;

    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;

    import com.example.hotel.Database.MysqlUser;
    import com.example.hotel.R;

    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    public class ManagerActivity extends AppCompatActivity {
        private String[] names = new String[]{
                "房间1,优惠大床房 128 大床1.8 22平米 无窗",
                "房间2,商务大床房 138 大床1.8 22-24平米 无窗",
                "房间3,主题房 218 圆床  25平米 无窗",
                "房间4,商务套房 388 大床1.8 45平米 有窗",
                "房间5,智控大床房 218 大床1.8 30平米 有窗",
                "房间6,标准双床房 108 双床 1.2 20平米 有窗",
                "房间7,商旅大床房 188 大床1.825平米 有窗",
                "房间8,温馨家庭房 188 多张床 30-35平米 有窗",
                "房间9,主题房 218 圆床  25平米 无窗",
                "房间10,商务大床房 145 大床1.8 23-25平米 有窗",

        };
        private int[] img = new int[]{R.drawable.room1,R.drawable.room2,R.drawable.room3,R.drawable.room4,R.drawable.room5,
                R.drawable.room6,R.drawable.room7,R.drawable.room8,R.drawable.room9,R.drawable.room10};
        private ListView list;
        private SimpleAdapter simpleAdapter;
        private int state,ID;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_manager);
            List<Map<String,Object>> ListItems=new ArrayList<Map<String, Object>>();
            {
                //利用循环将键和值一一对应放入map集合内。
               
    for (int i=0;i<names.length;i++){
                    Map<String,Object> listItem=new HashMap<String,Object>();
                    listItem.put("images",img[i]);
                    listItem.put("head",names[i]);
                    //加入list集合
                   
    ListItems.add(listItem);
                }
            }
            SimpleAdapter adapter=new SimpleAdapter(this,ListItems,R.layout.list_2, new String[]{"head","images"}, new int[]{R.id.Head,R.id.Img});
            ListView listView=(ListView)findViewById(R.id.managerlist);
            //ListView设置Adapter
           
    listView.setAdapter(adapter);
            //设置点击监听
           
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Thread thread=new Thread(new Runnable() {
                        @Override
                        public void run() {
                            ID=position+1;
                            MysqlUser mysqlUser=new MysqlUser();
                            try {
                                String sql="select roomstate from roominfo where roomid='"+ID+"'";
                                state=Integer.parseInt(mysqlUser.select(sql));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    thread.start();
                    try {
                        thread.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    if (state==1)
                         Toast.makeText(ManagerActivity.this, "房间"+ID+"已被预定",Toast.LENGTH_SHORT).show();
                    else  Toast.makeText(ManagerActivity.this, "房间"+ID+"未被预定",Toast.LENGTH_SHORT).show();
                }
            });
        }

    }
  • 相关阅读:
    electron webview加载远程preload方法
    vue 2.0使用笔记
    关于node的setTimeout的延时最大限制
    javascript的未知尺寸图片保持比例水平垂直居中函数
    node的“宏任务(macro-task)”和“微任务(micro-task)”机制
    windows git gui右键sublime/vs code打开当前文件编辑
    一个JavaScript组件都需要哪些基础api
    点击label时click事件被触发两次的坑
    javascript iframe相关操作
    javascript 写了个字符串组合的情况
  • 原文地址:https://www.cnblogs.com/zhaoyuxiao000/p/14908100.html
Copyright © 2011-2022 走看看