@Override public View getView(int position, View convertView, ViewGroup parent) { final ToDoItem toDoItem = mItems.get(position); LayoutInflater inflater = LayoutInflater.from(mContext); RelativeLayout itemLayout = (RelativeLayout) inflater.inflate(R.layout.todo_item, null); final TextView titleView = (TextView) itemLayout.findViewById(R.id.titleView); titleView.setText(toDoItem.getTitle()); final CheckBox statusView = (CheckBox) itemLayout.findViewById(R.id.statusCheckBox); statusView.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { log("Entered onCheckedChanged()"); ToDoItem.Status status = isChecked ? ToDoItem.Status.DONE : ToDoItem.Status.NOTDONE; toDoItem.setStatus(status); } }); final TextView priorityView = (TextView) itemLayout.findViewById(R.id.priorityView); priorityView.setText(toDoItem.getPriority().toString()); final TextView dateView = (TextView) itemLayout.findViewById(R.id.dateView); dateView.setText(ToDoItem.FORMAT.format(toDoItem.getDate())); // Return the View you just created return itemLayout; }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO - Get the current ToDoItem final ToDoItem toDoItem = (ToDoItem) getItem(position); // TODO - Inflate the View for this ToDoItem // from todo_item.xml. LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); RelativeLayout itemLayout = (RelativeLayout) inflater.inflate(R.layout.todo_item, null); // TODO - Fill in specific ToDoItem data // Remember that the data that goes in this View // corresponds to the user interface elements defined // in the layout file // TODO - Display Title in TextView final TextView titleView = (TextView) itemLayout.findViewById(R.id.titleView); titleView.setText(toDoItem.getTitle()); // TODO - Set up Status CheckBox final CheckBox statusView = (CheckBox) itemLayout.findViewById(R.id.statusCheckBox); statusView.setChecked(toDoItem.getStatus().equals(Status.DONE)); statusView.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { log("Entered onCheckedChanged()"); // TODO - Set up and implement an OnCheckedChangeListener, which // is called when the user toggles the status checkbox if (isChecked) { toDoItem.setStatus(Status.DONE); statusView.setChecked(true); } else { toDoItem.setStatus(Status.NOTDONE); statusView.setChecked(false); } } }); // TODO - Display Priority in a TextView final TextView priorityView = (TextView) itemLayout.findViewById(R.id.priorityView); priorityView.setText(toDoItem.getPriority().toString()); // TODO - Display Time and Date. // Hint - use ToDoItem.FORMAT.format(toDoItem.getDate()) to get date and time String final TextView dateView = (TextView) itemLayout.findViewById(R.id.dateView); dateView.setText(ToDoItem.FORMAT.format(toDoItem.getDate())); // Return the View you just created return itemLayout; }
@Override public View getView(int position, View convertView, ViewGroup parent) { final ToDoItem toDoItem = (ToDoItem) getItem(position); RelativeLayout itemLayout = null; itemLayout = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.todo_item, parent, false); // Fill in specific ToDoItem data // Remember that the data that goes in this View // corresponds to the user interface elements defined // in the layout file final TextView titleView = (TextView) itemLayout.findViewById(R.id.titleView); titleView.setText(toDoItem.getTitle()); final CheckBox statusView = (CheckBox) itemLayout.findViewById(R.id.statusCheckBox); if (toDoItem.getStatus() == ToDoItem.Status.DONE) statusView.setChecked(true); else statusView.setChecked(false); statusView.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toDoItem.setStatus(ToDoItem.Status.DONE); } else { toDoItem.setStatus(ToDoItem.Status.NOTDONE); } } }); final TextView priorityView = (TextView) itemLayout.findViewById(R.id.priorityView); priorityView.setText(toDoItem.getPriority().toString()); // Hint - use ToDoItem.FORMAT.format(toDoItem.getDate()) to get date and // time String final TextView dateView = (TextView) itemLayout.findViewById(R.id.dateView); dateView.setText(ToDoItem.FORMAT.format(toDoItem.getDate())); // Return the View you just created return itemLayout; // return convertView; }