如何在Android中的插槽类型中获取时间 [英] How to get time in slot type in android

查看:107
本文介绍了如何在Android中的插槽类型中获取时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取广告位类型的时间。例如,自行车商店从上午9点至晚上9点营业,因此我们可以在那段时间购买自行车。如果有人在晚上5点至晚上7点时段预订自行车,则应该显示上午9点至下午5点(可用),下午5点至7点(不可用)和晚上7点至9点(可用)时段。

I am trying to get time in slot type. for example bike shop is open 9am to 9pm so we can get the bike in that time. if anyone books a bike in evening 5 pm to 7 pm slot then it should show 9am to 5pm (available), 5pm to 7pm (not available) and 7pm to 9pm (available) slots.

,以便另一个想要预订同一辆自行车的用户可以了解该自行车的用户无法在该时段使用,而只能在可用的时段预订。

so that another user who wants to book same bike they can understand the bike is not available for this slot and he can book on only available slots.

我该如何实现?

推荐答案

用于保存数据的模型类

class TimeSlot {
String time;
boolean isAvailable;
} 

自定义适配器可更改gridview的内容

Custom adapter to change content of gridview

public class CustomListAdapter extends BaseAdapter {
    private  ArrayList<TimeSlot> list;

    private LayoutInflater mInflater;
    Context con;

    public CustomListAdapter(Context context, ArrayList<TimeSlot> list) {
        this.list = list;
this.con = context;
        mInflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return list.size();        
    }

    public Object getItem(int position) {
        return list.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) 
    {
        convertView = new TextView(con);
//set layout params or inflate xml layout
        convertView.setText(list.get(position).time);
        convertView.setEnabled(list.get(position).isAvailable);
        return convertView;
    }
}

主要活动

    List<TimeSolt> slots ;
    //assign the data from network or local...

    //create gridview from xml ...

    gridView.setColumnCount(3);

    //other properties goes here..

    //create custom adapter

    adapter = new CustomAdapter(this, slots);

    //other properties like onitemclick....



gridView.setAdapter(adapter);

            //create gridview from xml ...
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
                    @Override
                    public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int date) {
        //change the data of slots  according to date 
    //slots = newData; and call 
    adapter.notifyDataSetChanged();

                    }
                });

这篇关于如何在Android中的插槽类型中获取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆