Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBCursorAdapter extends CursorTreeAdapter {
- LayoutInflater mLayoutInflater;
- public DBCursorAdapter(Cursor cursor, Context context, boolean autoRequery) {
- super(cursor, context, true);
- this.mLayoutInflater = LayoutInflater.from(context);
- }
- @Override
- protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
- TextView test = (TextView) view.findViewById(R.id.detail_time);
- test.setText(cursor.getString(cursor.getColumnIndex("STARTTIME")) + " ~ " + cursor.getString(cursor.getColumnIndex("ENDTIME")));
- }
- @Override
- protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {
- TextView date = (TextView) view.findViewById(R.id.datelist);
- TextView todo = (TextView) view.findViewById(R.id.whattodo);
- date.setText(cursor.getString(cursor.getColumnIndex("STARTDATE")));
- todo.setText(cursor.getString(cursor.getColumnIndex("WHAT")));
- }
- @Override
- public Cursor getChildrenCursor(Cursor groupCursor) {
- return groupCursor;
- }
- @Override
- public int getChildrenCount(int groupPosition) {
- return 1;
- }
- @Override
- public void onGroupCollapsed(int groupPosition) {
- }
- @Override
- public void onGroupExpanded(int groupPosition) {
- }
- @Override
- public void setGroupCursor(Cursor cursor) {
- }
- @Override
- protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
- View childView = mLayoutInflater.inflate(R.layout.list_detail, null, false);
- return childView;
- }
- @Override
- protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
- View groupView = mLayoutInflater.inflate(R.layout.customadapter, null, false);
- return groupView;
- }
- }
- public class ManageSchedule extends AppCompatActivity {
- public static Context mContext;
- ExpandableListView list;
- DBHandler dbHandler;
- SQLiteDatabase db;
- String sql, toChild;
- Cursor cursor;
- final static String dbName = "Schedule.db";
- final static int dbVersion = 1;
- FloatingActionButton add;
- FloatingActionButton calendar;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.schedule_main);
- list = (ExpandableListView) findViewById(R.id.schedule);
- list.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
- @Override
- public void onGroupExpand(int groupPosition) {
- Toast.makeText(getApplicationContext(), String.valueOf(groupPosition), Toast.LENGTH_SHORT).show();
- }
- });
- Display newDisplay = getWindowManager().getDefaultDisplay();
- int width = newDisplay.getWidth();
- if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
- list.setIndicatorBounds(width - GetDipsFromPixel(20), width - GetDipsFromPixel(5));
- } else {
- list.setIndicatorBoundsRelative(width - GetDipsFromPixel(20), width - GetDipsFromPixel(5));
- }
- dbHandler = new DBHandler(this, dbName, null, dbVersion);
- mContext = this;
- selectDB();
- add = (FloatingActionButton) findViewById(R.id.add);
- add.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent addDetails = new Intent(ManageSchedule.this, AddDetails.class);
- startActivity(addDetails);
- }
- });
- calendar = (FloatingActionButton) findViewById(R.id.calendar);
- calendar.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent calendarView = new Intent(ManageSchedule.this, CalendarView.class);
- startActivity(calendarView);
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- public int GetDipsFromPixel(float pixels) {
- // Get the screen's density scale
- final float scale = getResources().getDisplayMetrics().density;
- // Convert the dps to pixels, based on density scale
- return (int) (pixels * scale + 0.5f);
- }
- public void selectDB() {
- db = dbHandler.getWritableDatabase();
- sql = "SELECT * FROM SCHEDULE zORDER BY STARTDATE, STARTTIME";
- //TextView what = (TextView) findViewById(R.id.whattodo);
- toChild = "SELECT STARTTIME, ENDTIME FROM SCHEDULE WHERE WHAT = ' ddd '";
- cursor = db.rawQuery(sql, null);
- if (cursor.getCount() > 0) {
- DBCursorAdapter dbAdapter = new DBCursorAdapter(cursor, this, true);
- dbAdapter.getChildrenCursor(db.rawQuery(toChild, null));
- list.setAdapter(dbAdapter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement