如何在 android 中的插槽类型中获取时间
How to get time in slot type in android
我正在尝试获取时段类型的时间。例如,自行车商店的营业时间为上午 9 点至晚上 9 点,因此我们可以在那段时间拿到自行车。如果有人在晚上 5 点到 7 点时段预订自行车,那么它应该显示上午 9 点到下午 5 点(可用)、下午 5 点到晚上 7 点(不可用)和晚上 7 点到晚上 9 点(可用)时段。
以便另一个想要预订同一辆自行车的用户可以了解该自行车不能用于此时段,他只能预订可用的时段。
我怎么实现的?
用于保存数据的模型class
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();
}
});
我正在尝试获取时段类型的时间。例如,自行车商店的营业时间为上午 9 点至晚上 9 点,因此我们可以在那段时间拿到自行车。如果有人在晚上 5 点到 7 点时段预订自行车,那么它应该显示上午 9 点到下午 5 点(可用)、下午 5 点到晚上 7 点(不可用)和晚上 7 点到晚上 9 点(可用)时段。
以便另一个想要预订同一辆自行车的用户可以了解该自行车不能用于此时段,他只能预订可用的时段。
我怎么实现的?
用于保存数据的模型class
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();
}
});