2016-07-27 72 views
0

我試圖創建一個類似於在白天模式,在那裏你通過天刷卡谷歌日曆日曆,看看小時日曆刷卡查看Android的

我卡在如何更新日期用戶揮筆

這是我有:

的ListView適配器

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在哪裏設置適配器的的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); 
} 

輕掃適配器

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

}

而且我CalendarFragment,我填充與天

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


} 

它的工作的時間列表視圖,可我就是」找出更新日期的方法。 我嘗試了一些東西,如存儲在SwipeAdapter上給出的位置,並從getInstance()中添加或減去一天,但它似乎沒有工作

任何幫助,將不勝感激。

回答

0

好吧,我不知道我是否可以明確地回答你的問題,但我可以幫助擺脫一些光線或給你思考的食物。

在我的代碼中,我設置了一個View Pager Listener。如果你可以在你的代碼中做到這一點,我認爲它會給你你正在尋找的功能。

下面是從我的應用程序的一個例子:

public void setViewPagerListener() 
     { 
      view_pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() 
      { 
       @Override 
       public void onPageSelected(int position) 
       { 
        //Log.i(TAG, "position: " + position); 
        // on changing the page 
        // make respected tab selected 
        //actionBar.setSelectedNavigationItem(position); 
       } 

       @Override 
       public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) 
       { 
        //Log.i(TAG, "positionOffset: " + positionOffset); 
        if (positionOffset >= .7) 
        { 
         handler_scrim_alpha.post(setScrimAlphaRunnable(.1f)); 
        } 
        else if (positionOffset < .7 && positionOffset >= .4) 
        { 
         handler_scrim_alpha.post(setScrimAlphaRunnable(.3f)); 
        } 
        else if (positionOffset < .5 & positionOffset >= .2) 
        { 
         handler_scrim_alpha.post(setScrimAlphaRunnable(.5f)); 
        } 
        else if (positionOffset < .2 && !(positionOffset == 0)) 
        { 
         handler_scrim_alpha.post(setScrimAlphaRunnable(.7f)); 
        } 
       } 

       @Override 
       public void onPageScrollStateChanged(int scrollState) 
       { 
        /*scrollState == 0 when the pager is idle and has finished it's scroll.*/ 
        scroll_state_global = scrollState; 

        if (scrollState == 0 && view_pager.getCurrentItem() == 1) 
        { 
         scroll_state_global = -1; 
         frame_input_scrim.setVisibility(View.INVISIBLE); 
         view_pager.setVisibility(View.INVISIBLE); 
        } 
       } 
      }); 
     }