Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. public class DBCursorAdapter extends CursorTreeAdapter {
  2.  
  3. LayoutInflater mLayoutInflater;
  4.  
  5. public DBCursorAdapter(Cursor cursor, Context context, boolean autoRequery) {
  6. super(cursor, context, true);
  7. this.mLayoutInflater = LayoutInflater.from(context);
  8. }
  9.  
  10. @Override
  11. protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
  12. TextView test = (TextView) view.findViewById(R.id.detail_time);
  13.  
  14. test.setText(cursor.getString(cursor.getColumnIndex("STARTTIME")) + " ~ " + cursor.getString(cursor.getColumnIndex("ENDTIME")));
  15. }
  16.  
  17. @Override
  18. protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {
  19. TextView date = (TextView) view.findViewById(R.id.datelist);
  20. TextView todo = (TextView) view.findViewById(R.id.whattodo);
  21.  
  22. date.setText(cursor.getString(cursor.getColumnIndex("STARTDATE")));
  23. todo.setText(cursor.getString(cursor.getColumnIndex("WHAT")));
  24. }
  25.  
  26.  
  27. @Override
  28. public Cursor getChildrenCursor(Cursor groupCursor) {
  29. return groupCursor;
  30. }
  31.  
  32. @Override
  33. public int getChildrenCount(int groupPosition) {
  34. return 1;
  35. }
  36.  
  37. @Override
  38. public void onGroupCollapsed(int groupPosition) {
  39. }
  40.  
  41. @Override
  42. public void onGroupExpanded(int groupPosition) {
  43. }
  44.  
  45. @Override
  46. public void setGroupCursor(Cursor cursor) {
  47.  
  48. }
  49.  
  50. @Override
  51. protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
  52. View childView = mLayoutInflater.inflate(R.layout.list_detail, null, false);
  53.  
  54. return childView;
  55. }
  56.  
  57. @Override
  58. protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
  59. View groupView = mLayoutInflater.inflate(R.layout.customadapter, null, false);
  60.  
  61. return groupView;
  62. }
  63. }
  64.  
  65. public class ManageSchedule extends AppCompatActivity {
  66.  
  67. public static Context mContext;
  68.  
  69. ExpandableListView list;
  70. DBHandler dbHandler;
  71. SQLiteDatabase db;
  72. String sql, toChild;
  73. Cursor cursor;
  74.  
  75. final static String dbName = "Schedule.db";
  76. final static int dbVersion = 1;
  77.  
  78. FloatingActionButton add;
  79. FloatingActionButton calendar;
  80.  
  81. @Override
  82. protected void onCreate(Bundle savedInstanceState) {
  83. super.onCreate(savedInstanceState);
  84. setContentView(R.layout.schedule_main);
  85.  
  86. list = (ExpandableListView) findViewById(R.id.schedule);
  87.  
  88. list.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
  89. @Override
  90. public void onGroupExpand(int groupPosition) {
  91. Toast.makeText(getApplicationContext(), String.valueOf(groupPosition), Toast.LENGTH_SHORT).show();
  92. }
  93. });
  94.  
  95. Display newDisplay = getWindowManager().getDefaultDisplay();
  96. int width = newDisplay.getWidth();
  97. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
  98. list.setIndicatorBounds(width - GetDipsFromPixel(20), width - GetDipsFromPixel(5));
  99. } else {
  100. list.setIndicatorBoundsRelative(width - GetDipsFromPixel(20), width - GetDipsFromPixel(5));
  101. }
  102.  
  103. dbHandler = new DBHandler(this, dbName, null, dbVersion);
  104.  
  105. mContext = this;
  106. selectDB();
  107.  
  108. add = (FloatingActionButton) findViewById(R.id.add);
  109. add.setOnClickListener(new View.OnClickListener() {
  110. @Override
  111. public void onClick(View v) {
  112. Intent addDetails = new Intent(ManageSchedule.this, AddDetails.class);
  113. startActivity(addDetails);
  114. }
  115. });
  116.  
  117. calendar = (FloatingActionButton) findViewById(R.id.calendar);
  118. calendar.setOnClickListener(new View.OnClickListener() {
  119. @Override
  120. public void onClick(View v) {
  121. Intent calendarView = new Intent(ManageSchedule.this, CalendarView.class);
  122. startActivity(calendarView);
  123. }
  124. });
  125. }
  126.  
  127. @Override
  128. public boolean onCreateOptionsMenu(Menu menu) {
  129. // Inflate the menu; this adds items to the action bar if it is present.
  130. getMenuInflater().inflate(R.menu.menu_main, menu);
  131. return true;
  132. }
  133.  
  134. @Override
  135. public boolean onOptionsItemSelected(MenuItem item) {
  136. // Handle action bar item clicks here. The action bar will
  137. // automatically handle clicks on the Home/Up button, so long
  138. // as you specify a parent activity in AndroidManifest.xml.
  139. int id = item.getItemId();
  140.  
  141. //noinspection SimplifiableIfStatement
  142. if (id == R.id.action_settings) {
  143. return true;
  144. }
  145.  
  146. return super.onOptionsItemSelected(item);
  147. }
  148.  
  149. public int GetDipsFromPixel(float pixels) {
  150. // Get the screen's density scale
  151. final float scale = getResources().getDisplayMetrics().density;
  152. // Convert the dps to pixels, based on density scale
  153. return (int) (pixels * scale + 0.5f);
  154. }
  155.  
  156. public void selectDB() {
  157. db = dbHandler.getWritableDatabase();
  158. sql = "SELECT * FROM SCHEDULE zORDER BY STARTDATE, STARTTIME";
  159.  
  160. //TextView what = (TextView) findViewById(R.id.whattodo);
  161.  
  162. toChild = "SELECT STARTTIME, ENDTIME FROM SCHEDULE WHERE WHAT = ' ddd '";
  163.  
  164. cursor = db.rawQuery(sql, null);
  165. if (cursor.getCount() > 0) {
  166. DBCursorAdapter dbAdapter = new DBCursorAdapter(cursor, this, true);
  167. dbAdapter.getChildrenCursor(db.rawQuery(toChild, null));
  168. list.setAdapter(dbAdapter);
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement