gpt4 book ai didi

java - 如何在android中的插槽类型中获取时间

转载 作者:行者123 更新时间:2023-11-30 04:53:46 26 4
gpt4 key购买 nike

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

以便另一个想要预订同一辆自行车的用户可以了解该自行车不适用于该时段,他只能预订可用的时段。

我如何实现这一目标?

enter image description here

最佳答案

保存数据的模型类

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;
}
}

主要 Activity

    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();

}
});

关于java - 如何在android中的插槽类型中获取时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59573807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com