@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment view = inflater.inflate(R.layout.fragment_present, container, false); txtviewIntro = (TextView) view.findViewById(R.id.txtview_goals_intro); txtviewIntro.setTextColor(Color.GRAY); fab = (FloatingActionButton) view.findViewById(R.id.btn_action_button); fab.setOnClickListener(this); goalsMap = new HashMap<String, Integer>(); MySQLiteHelper db = new MySQLiteHelper(activity); List<Goal> goals = db.getAllGoals(); db.close(); displayGoals(display_present); goalsListView = (ListView) view.findViewById(R.id.listview_goals); goalsListView.setAdapter(goalAdapter); goalsListView.setOnItemClickListener(this); for (Goal goal : goals) { goalsMap.put(goal.getTitle(), goal.getId()); } fab.attachToListView(goalsListView); return view; }
public void displayGoals(boolean display_present) { this.display_present = display_present; MySQLiteHelper db = new MySQLiteHelper(activity); List<Goal> goals = db.getAllGoals(); goalsToDisplay.clear(); for (Goal goal : goals) { if (goal.getComplete() == Goal.INCOMPLETE && display_present) { goalsToDisplay.add(goal); } else if (goal.getComplete() == Goal.COMPLETE && !display_present) { goalsToDisplay.add(goal); } } if (goalAdapter == null) { goalAdapter = new GoalAdapter(activity, R.layout.goal_listview_row, goalsToDisplay); } else { goalsListView.post( new Runnable() { @Override public void run() { goalAdapter.notifyDataSetChanged(); } }); } if (goals.size() == 0 && display_present) { txtviewIntro.setText("Press the action button to add a goal."); txtviewIntro.setVisibility(View.VISIBLE); } else if (!display_present && Goal.getCompleteGoals(goals).size() == 0) { txtviewIntro.setText("When you complete a goal it will be displayed here."); txtviewIntro.setVisibility(View.VISIBLE); } else { txtviewIntro.setVisibility(View.GONE); } }