Exemplo n.º 1
0
  // Code to run on startup
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_todolist, container, false);

    // Get the datasource for Tasks
    datasource = new TasksDataSource(this.getActivity());
    datasource.open();

    // Return a list of tasks saved in the database
    ArrayList<Task> tasks = datasource.getAllTasks();

    // Use the SimpleCursorAdapter to show the elements in a ListView
    adapter = new TaskAdapter(this.getActivity(), R.layout.todo_row, tasks);
    setListAdapter(adapter);

    // Find the TextViews for inputting task information
    title = (TextView) v.findViewById(R.id.item1);
    date = (TextView) v.findViewById(R.id.item1Date);
    desc = (TextView) v.findViewById(R.id.item1Des);

    // Make buttonpresses call onClick in this class
    Button addTask = (Button) v.findViewById(R.id.addTask);
    addTask.setOnClickListener(this);
    Button removeTask = (Button) v.findViewById(R.id.removeTask);
    removeTask.setOnClickListener(this);

    return v;
  }
Exemplo n.º 2
0
 @Override
 public void onResume() {
   datasource.open();
   super.onResume();
 }