Back to project page todo-android.
The source code is released under:
MIT License
If you think the Android project todo-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.ishan.todo.app; /*from ww w. jav a 2 s .co m*/ import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.view.WindowManager; import android.widget.TextView; public class EditItemActivity extends ActionBarActivity { private EditText etEditItem; private int editItemIndex; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_item); // Set Title for Activity getSupportActionBar().setTitle("Edit Item"); String editItemText = getIntent().getStringExtra("todoItem"); editItemIndex = getIntent().getIntExtra("itemIndex", -1); etEditItem = (EditText) findViewById(R.id.etEditItem); setupReturnKeyListenerForEditText(); populateEditText(editItemText); } /* Setup listener to call onSave when return key/done button is pressed on the keyboard */ private void setupReturnKeyListenerForEditText() { etEditItem.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int i, KeyEvent keyEvent) { boolean handled = false; if (i == EditorInfo.IME_ACTION_DONE) { onSave(v); handled = true; } return handled; } }); } public void populateEditText(String editItemText) { etEditItem.setText(editItemText); etEditItem.setSelection(editItemText.length()); etEditItem.requestFocus(); // Set keyboard to appear after etEditItem is in focus getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } public void onSave(View v) { Intent editedTextData = new Intent(); editedTextData.putExtra("editedItemText", etEditItem.getText().toString()); editedTextData.putExtra("editedItemIndex", editItemIndex); setResult(RESULT_OK, editedTextData); this.finish(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.edit_item, 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(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }