I'm trying to create a calendar similar to Google Calendar on Day mode, where you swipe through the days and see the hours
I'm stuck on how to update the date as the user swipes
here's what I have:
ListView Adapter
public class ListViewItems extends ArrayAdapter{
private Activity context;
private ArrayList<String> horarios;
public ListViewItems(Activity c, ArrayList<String> h){
super(c, R.layout.listview_item, h);
this.context = c;
this.horarios = h;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup){
LayoutInflater inflater = context.getLayoutInflater();
View v = inflater.inflate(R.layout.listview_item, null, true);
TextView hor = (TextView)v.findViewById(R.id.horario);
hor.setText(horarios.get(position));
return v;
}
}
EventsFragment where I set the adapter for the Viewpage
public class EventsFragment extends Fragment {
private SharedPreferences.Editor editor;
private SharedPreferences sharedPref;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_events, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
ViewPager vp = (ViewPager)view.findViewById(R.id.viewpager);
SwipeAdapter sp = new SwipeAdapter(getActivity().getSupportFragmentManager());
vp.setAdapter(sp);
vp.setCurrentItem(249);
}
The Swipe Adapter
public class SwipeAdapter extends FragmentStatePagerAdapter {
public SwipeAdapter(FragmentManager fm){
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = new CalendarFragment();
return fragment;
}
@Override
public int getCount() {
return 500;
}
}
And my CalendarFragment where I populate the listView with the hours of the day
public class CalendarFragment extends Fragment {
private Integer currentPosition;
public CalendarFragment(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_calendar, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
TextView text = (TextView)view.findViewById(R.id.day);
Calendar currentDate = Calendar.getInstance();
String day = Integer.toString(currentDate.get(Calendar.DAY_OF_MONTH));
text.setText(day);
ArrayList<String> horariosFixos = new ArrayList<String>();
horariosFixos.add("01:00");
horariosFixos.add("02:00");
horariosFixos.add("03:00");
horariosFixos.add("04:00");
horariosFixos.add("05:00");
horariosFixos.add("06:00");
horariosFixos.add("07:00");
horariosFixos.add("08:00");
horariosFixos.add("09:00");
horariosFixos.add("10:00");
horariosFixos.add("11:00");
horariosFixos.add("12:00");
horariosFixos.add("13:00");
horariosFixos.add("14:00");
horariosFixos.add("15:00");
horariosFixos.add("16:00");
horariosFixos.add("17:00");
horariosFixos.add("18:00");
horariosFixos.add("19:00");
horariosFixos.add("20:00");
horariosFixos.add("21:00");
horariosFixos.add("22:00");
horariosFixos.add("23:00");
horariosFixos.add("00:00");
ListViewItems events = new ListViewItems(getActivity(),horariosFixos);
ListView events_list = (ListView)view.findViewById(R.id.events_list);
events_list.setAdapter(events);
}
It's working, but I just can't figure out a way to update the date. I tried a few things like storing the position given on SwipeAdapter and add or subtract a day from getInstance() but it didn't seem to work
Any help would be appreciated.