Android Open Source - simple-todo Edit Item Activity

From Project

Back to project page simple-todo.


The source code is released under:

MIT License

If you think the Android project simple-todo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.fcduarte.todoapp.activity;
//from w ww.  ja  v a  2s  .c om
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.fcduarte.todoapp.R;

public class EditItemActivity extends Activity {
  public static final String ITEM_DESCRIPTION = "item_description";
  public static final String ITEM_ID = "item_id";
  protected void onCreate(Bundle savedInstanceState) {

    if (savedInstanceState == null) {
          .add(, new EditItemFragment()).commit();

  public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;

  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();
    if (id == {
      return true;
    return super.onOptionsItemSelected(item);
  public static class EditItemFragment extends Fragment {

    private EditText etEditItem;
    private String itemDescription;
    private Long itemId;
    private Button btnSaveItem;
    public EditItemFragment() {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_edit_item,
          container, false);

      Intent intent = getActivity().getIntent();
      itemDescription = intent.getStringExtra(EditItemActivity.ITEM_DESCRIPTION);
      itemId = intent.getLongExtra(EditItemActivity.ITEM_ID, -1);
      etEditItem = (EditText) rootView.findViewById(;
      btnSaveItem = (Button) rootView.findViewById(;
      btnSaveItem.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          String newItemDescription = etEditItem.getText().toString();
          if (newItemDescription.equals(itemDescription)) {
          } else {
            Intent data = new Intent();
            data.putExtra(EditItemActivity.ITEM_DESCRIPTION, newItemDescription);
            data.putExtra(EditItemActivity.ITEM_ID, itemId);
            getActivity().setResult(TodoActivity.RESULT_OK, data);
      return rootView;


Java Source Code List