【问题标题】:How to get time in slot type in android如何在android中的插槽类型中获取时间
【发布时间】:2020-01-03 05:53:49
【问题描述】:

我正在尝试在插槽类型中获得时间。例如自行车店早上 9 点到晚上 9 点营业,所以我们可以在那个时间拿到自行车。如果有人在晚上 5 点到 7 点的时段预订自行车,那么它应该显示上午 9 点到下午 5 点(可用)、下午 5 点到 7 点(不可用)和晚上 7 点到 9 点(可用)的时段。

以便其他想要预订同一辆自行车的用户可以理解该自行车不适用于此插槽,并且他只能在可用插槽上进行预订。

我是怎么做到的?

【问题讨论】:

  • 那么你需要两个时间槽 1 开始时间和结束时间秒。

标签: java android dynamic-arrays java-time android-timepicker


【解决方案1】:

保存数据的模型类

class TimeSlot {
String time;
boolean isAvailable;
} 

自定义适配器来改变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();

                    }
                });

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
  • 1970-01-01
  • 2021-03-17
  • 1970-01-01
  • 1970-01-01
  • 2018-10-24
  • 2022-06-29
相关资源
最近更新 更多