KiloWhiskay

Untitled

Oct 28th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package me.k.cal.fragment;
  2.  
  3. import me.k.cal.R;
  4. import me.k.cal.struct.WLEvent;
  5. import android.app.Fragment;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.ListView;
  11.  
  12. public class EventDisplayFragment extends Fragment
  13. {
  14. private WLEvent[] m_events;
  15.  
  16. @Override
  17. public void onSaveInstanceState(Bundle p_state)
  18. {
  19. if(m_events != null)
  20. p_state.putParcelableArray("EVENTS", m_events);
  21. }
  22.  
  23. @Override
  24. public View onCreateView(LayoutInflater p_inflater, ViewGroup p_container, Bundle p_prev_state)
  25. {
  26. return p_inflater.inflate(R.layout.fragment_main, p_container, false);
  27. }
  28.  
  29. @Override
  30. public void onActivityCreated(Bundle p_prev_state)
  31. {
  32. super.onActivityCreated(p_prev_state);
  33.  
  34. if(p_prev_state != null && p_prev_state.containsKey("EVENTS"))
  35. m_events = (WLEvent[])p_prev_state.getParcelableArray("EVENTS");
  36. }
  37.  
  38. public int getIndex()
  39. {
  40. try
  41. {
  42. return this.getListView().getFirstVisiblePosition();
  43. }
  44. catch(Exception e){ return 0; }
  45. }
  46.  
  47. public int getTop()
  48. {
  49. try
  50. {
  51. return this.getListView().getChildAt(0).getTop();
  52. }
  53. catch(Exception e){ return 0; }
  54. }
  55.  
  56. public void setListViewPos(int p_ind, int p_top)
  57. {
  58. if(this.getListView().getCount() != 0)
  59. this.getListView().setSelectionFromTop(p_ind, p_top);
  60. }
  61.  
  62. public void setEvents(WLEvent[] p_events)
  63. {
  64. m_events = p_events;
  65. }
  66.  
  67. public WLEvent[] getEvents()
  68. {
  69. return m_events;
  70. }
  71.  
  72. private ListView getListView()
  73. {
  74. return (ListView)getView().findViewById(R.id.main_events);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment