How To Get Time In Slot Type In Android
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 shou
Solution 1:
A model class to hold data
classTimeSlot{
String time;
boolean isAvailable;
}
Custom adapter to change content of gridview
publicclassCustomListAdapterextendsBaseAdapter {
private ArrayList<TimeSlot> list;
private LayoutInflater mInflater;
Context con;
publicCustomListAdapter(Context context, ArrayList<TimeSlot> list) {
this.list = list;
this.con = context;
mInflater = LayoutInflater.from(context);
}
publicintgetCount() {
return list.size();
}
public Object getItem(int position) {
return list.get(position);
}
publiclonggetItemId(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;
}
}
Main 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 = newCustomAdapter(this, slots);
//other properties like onitemclick....
gridView.setAdapter(adapter);
//create gridview from xml ...
calendarView.setOnDateChangeListener(newCalendarView.OnDateChangeListener() {
@OverridepublicvoidonSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int date) {
//change the data of slots according to date //slots = newData; and call
adapter.notifyDataSetChanged();
}
});
Post a Comment for "How To Get Time In Slot Type In Android"