Android Open Source - trivial-lists Generic Editor Dialog Fragment

From Project

Back to project page trivial-lists.


The source code is released under:

MIT License

If you think the Android project trivial-lists 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 org.hbabcock.triviallists;
//from w  w  w .j a  v a  2  s  .c  o m
import java.util.UUID;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class GenericEditorDialogFragment extends DialogFragment {
  private static final String TAG = "GenericEditorDialogFragment";
  public static final String EXTRA_GENERIC_ID = "org.hbabcock.triviallist.generic_id";
  public static final String EXTRA_GENERIC_NAME = "org.hbabcock.triviallist.generic_name";
  public static final String EXTRA_EDIT_MODE = "org.hbabcock.triviallist.edit_mode";
  public static final int REQUEST_EDIT = 10;
  public static final int REQUEST_NEW = 11;

  private String mId;
  private String mName;
  private View mView;
  public static GenericEditorDialogFragment newInstance(UUID id, String name){
    Bundle args = new Bundle();
    args.putString(EXTRA_GENERIC_ID, id.toString());
    args.putString(EXTRA_GENERIC_NAME, name);
    GenericEditorDialogFragment fragment = new GenericEditorDialogFragment();
    return fragment;
  public Dialog onCreateDialog(Bundle savedInstanceState){
    mId = new String(getArguments().getString(EXTRA_GENERIC_ID));
    mName = new String(getArguments().getString(EXTRA_GENERIC_NAME));

    mView = getActivity().getLayoutInflater().inflate(R.layout.generic_editor_dialog_fragment, null);
    ((EditText) mView.findViewById(;
    Integer stringId;
    if (getTargetRequestCode() == REQUEST_NEW){
      stringId = R.string.category_editor_title_new;
      stringId = R.string.category_editor_title_edit;
    return new AlertDialog.Builder(getActivity())
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
  private void sendResult(int resultCode){
    if (getTargetFragment() == null)

    Intent i = new Intent();
    i.putExtra(EXTRA_GENERIC_ID, mId);
    i.putExtra(EXTRA_GENERIC_NAME, ((EditText)mView.findViewById(;
    getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, i);

Java Source Code List