Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

In this page you can find the example usage for android.app Dialog findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:com.aegiswallet.actions.MainActivity.java

private void doBackupReminder() {

    if (System.currentTimeMillis() - application.lastReminderTime < 60000)
        return;// w  w w .  j  a  v a  2  s .  c o  m

    String lastBackupString = prefs.getString(Constants.LAST_BACKUP_DATE, null);
    int lastBackupNumAddresses = prefs.getInt(Constants.LAST_BACKUP_NUM_ADDRESSES, 0);

    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.backup_reminder_prompt);

    TextView backupText = (TextView) dialog.findViewById(R.id.backup_reminder_prompt_text);

    Button cancelButton = (Button) dialog.findViewById(R.id.backup_reminder_prompt_cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    final Button okayButton = (Button) dialog.findViewById(R.id.backup_reminder_prompt_ok_button);

    okayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();

            if (nfcEnabled) {
                Intent intent = new Intent(context, NFCActivity.class);
                intent.putExtra("nfc_action", "backup");
                startActivity(intent);
            } else
                application.showPasswordPrompt(context, Constants.ACTION_BACKUP);
        }
    });

    try {

        if (dialog.isShowing())
            return;

        if (lastBackupString != null) {
            Date lastBackupDate = Constants.backupDateFormat.parse(lastBackupString);
            long currentDate = System.currentTimeMillis();
            long difference = currentDate - lastBackupDate.getTime();

            long days = TimeUnit.MILLISECONDS.toDays(difference);
            int keyChainSize = wallet.getKeychainSize();

            if (days > 6) {
                dialog.show();
                application.lastReminderTime = System.currentTimeMillis();
            } else if (!prefs.contains(Constants.LAST_BACKUP_NUM_ADDRESSES)) {
                dialog.show();
                application.lastReminderTime = System.currentTimeMillis();

            } else if (keyChainSize > lastBackupNumAddresses) {
                backupText.setText(getString(R.string.backup_reminder_new_address));
                dialog.show();
                application.lastReminderTime = System.currentTimeMillis();
            }

        } else {
            application.lastReminderTime = System.currentTimeMillis();
            dialog.show();
        }

    } catch (ParseException e) {
        Log.d(TAG, e.getMessage());
    }
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java

private void createToolSymbolExplanationDialog() {
    final Dialog dialog = dialogInterface.getDialog(getActivity(), R.layout.dialog_tool_legend,
            R.string.tool_legend);/*  w  w  w  .  jav a 2  s. c om*/

    TableLayout tableLayout = (TableLayout) dialog.findViewById(R.id.tool_legend_table_layout);
    Button dismissButton = (Button) dialog.findViewById(R.id.tool_legend_dismiss_button);

    for (ToolType toolType : ToolType.values()) {
        View toolLegendRow = rowsInterface
                .getToolLegendRow(getActivity(), toolType.getHexColorValue(), toolType.toString()).getView();
        tableLayout.addView(toolLegendRow);
    }

    dismissButton.setOnClickListener(onClickListenerInterface.getDismissDialogListener(dialog));

    dialog.show();
}

From source file:com.markuspage.android.atimetracker.Tasks.java

@Override
protected void onPrepareDialog(int id, Dialog d) {
    EditText textView;/*from  ww w .ja  v a 2  s .  co  m*/
    switch (id) {
    case ADD_TASK:
        textView = (EditText) d.findViewById(R.id.task_edit_name_edit);
        textView.setText("");
        break;
    case EDIT_TASK:
        textView = (EditText) d.findViewById(R.id.task_edit_name_edit);
        textView.setText(selectedTask.getTaskName());
        break;
    default:
        break;
    }
}

From source file:org.thoughtland.xlocation.ActivityApp.java

@SuppressLint("InflateParams")
public static void showHelp(ActivityBase context, View parent, Hook hook) {
    // Build dialog
    Dialog dlgHelp = new Dialog(context);
    dlgHelp.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dlgHelp.setTitle(R.string.app_name);
    dlgHelp.setContentView(R.layout.helpfunc);
    dlgHelp.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, context.getThemed(R.attr.icon_launcher));
    dlgHelp.setCancelable(true);// w w w.  j ava2  s  .  co  m

    // Set title
    TextView tvTitle = (TextView) dlgHelp.findViewById(R.id.tvTitle);
    tvTitle.setText(hook.getName());

    // Set info
    TextView tvInfo = (TextView) dlgHelp.findViewById(R.id.tvInfo);
    tvInfo.setText(Html.fromHtml(hook.getAnnotation()));
    tvInfo.setMovementMethod(LinkMovementMethod.getInstance());

    // Set permissions
    String[] permissions = hook.getPermissions();
    if (permissions != null && permissions.length > 0)
        if (!permissions[0].equals("")) {
            TextView tvPermissions = (TextView) dlgHelp.findViewById(R.id.tvPermissions);
            tvPermissions.setText(Html.fromHtml(TextUtils.join("<br />", permissions)));
        }

    dlgHelp.show();
}

From source file:org.wso2.emm.agent.AuthenticationActivity.java

/**
 * Show the license text retrieved from the server.
 *
 * @param message Message text to be shown as the license.
 * @param title   Title of the license.//  w  ww  . ja  va 2 s.  c  om
 */
private void showAgreement(final String message, String title) {
    AuthenticationActivity.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom_terms_popup);
            dialog.setTitle(Constants.EULA_TITLE);
            dialog.setCancelable(false);

            WebView webView = (WebView) dialog.findViewById(R.id.webview);

            webView.loadDataWithBaseURL(null, message, Constants.MIME_TYPE, Constants.ENCODING_METHOD, null);

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel);

            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Preference.putBoolean(context, Constants.PreferenceFlag.IS_AGREED, true);
                    dialog.dismiss();
                    //load the next intent based on ownership type
                    checkManifestPermissions();
                }
            });

            cancelButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    CommonUtils.clearClientCredentials(context);
                    cancelEntry();
                }
            });

            dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_SEARCH
                            && event.getRepeatCount() == Constants.DEFAILT_REPEAT_COUNT) {
                        return true;
                    } else if (keyCode == KeyEvent.KEYCODE_BACK
                            && event.getRepeatCount() == Constants.DEFAILT_REPEAT_COUNT) {
                        return true;
                    }
                    return false;
                }
            });

            dialog.show();
        }
    });
}

From source file:com.example.linhdq.test.documents.creation.NewDocumentActivity.java

@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
    switch (id) {
    case EDIT_TITLE_DIALOG_ID:
        final Uri documentUri = Uri.parse(args.getString(DIALOG_ARG_DOCUMENT_URI));
        final String oldTitle = args.getString(DIALOG_ARG_TITLE);
        final EditText edit = (EditText) dialog.findViewById(R.id.edit_title);
        edit.setText(oldTitle);/*from   ww w.  j av a  2s .  c  o m*/
        AlertDialog alertDialog = (AlertDialog) dialog;
        Button okButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
        okButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final String title = edit.getText().toString();
                saveTitle(title, documentUri);
            }
        });
        break;
    case HINT_DIALOG_ID:
        break;
    default:
        if (args != null) {
            final int max = args.getInt(DIALOG_ARG_MAX);
            final int progress = args.getInt(DIALOG_ARG_PROGRESS);
            // final int secondaryProgress =
            // args.getInt(DIALOG_ARG_SECONDARY_PROGRESS);
            final String message = args.getString(DIALOG_ARG_MESSAGE);
            final String title = args.getString(DIALOG_ARG_TITLE);
            if (id == PDF_PROGRESS_DIALOG_ID) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        pdfProgressDialog.setProgress(progress);
                        pdfProgressDialog.setMax(max);
                        if (message != null) {
                            pdfProgressDialog.setMessage(message);
                        }
                        if (title != null) {
                            pdfProgressDialog.setTitle(title);
                        }
                    }
                });

            } else if (id == DELETE_PROGRESS_DIALOG_ID) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        deleteProgressDialog.setProgress(progress);
                        deleteProgressDialog.setMax(max);
                        if (message != null) {
                            deleteProgressDialog.setMessage(message);
                        }
                    }
                });
            }
        }
    }
    super.onPrepareDialog(id, dialog, args);
}

From source file:com.birdeye.MainActivity.java

private void removeAdsDialog() {

    final Dialog dialog = new Dialog(MainActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.progress_pre);

    TextView tv_pay15 = (TextView) dialog.findViewById(R.id.tv_pay15);

    tv_pay15.setOnClickListener(new View.OnClickListener() {
        @Override//from   w ww.  j a  v  a  2  s  .c  om
        public void onClick(View v) {

            if (!BillingProcessor.isIabServiceAvailable(MainActivity.this)) {
                showToast(
                        "In-app billing service is unavailable, please upgrade Android Market/Play to version >= 3.9.16");
            }

            else {

                //    asdasd

                //  onFuturePaymentPressed(v);
                bp.subscribe(MainActivity.this, SUBSCRIPTION_ID);

            }

            dialog.dismiss();

        }
    });

    dialog.setCancelable(true);

    dialog.show();

}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityJourney.java

/**
 * sends a message to the driver of a journey
 *//*from  w  w  w .  j ava  2s .  c  om*/
private void sendMessageToDriver() {

    final Dialog customDialog = new Dialog(this);
    customDialog.setContentView(R.layout.custom_dialog_layout);
    customDialog.setTitle("Message");

    final List<String> spinnerArray = new ArrayList<String>();
    spinnerArray.add("Everyone");
    if (!getApp().getSelectedJourney().getDriver().equals(getApp().getUser())) {
        spinnerArray.add(getApp().getSelectedJourney().getDriver().getFullName());
    }

    for (int i = 0; i < getApp().getSelectedJourney().getHitchhikers().size(); i++) {
        if (!getApp().getSelectedJourney().getHitchhikers().get(i).equals(getApp().getUser())) {
            spinnerArray.add(getApp().getSelectedJourney().getHitchhikers().get(i).getFullName());
        }
    }

    final Spinner spinner = (Spinner) customDialog.findViewById(R.id.spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivityJourney.this,
            android.R.layout.simple_spinner_item, spinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    ImageView sendBtn = (ImageView) customDialog.findViewById(R.id.sendBtn);
    final EditText input = (EditText) customDialog.findViewById(R.id.input);

    sendBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            User mid = getApp().getUser();
            if (spinner.getSelectedItem().toString().equals("Everyone")) {
                if (input.getText().toString().equals("")) {
                    input.setHint("Please fill in your message");
                    Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message",
                            Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                } else {
                    List<User> userList = new ArrayList<User>();
                    userList.add(getApp().getSelectedJourney().getDriver());
                    for (int k = 0; k < getApp().getSelectedJourney().getHitchhikers().size(); k++) {
                        userList.add(getApp().getSelectedJourney().getHitchhikers().get(k));
                    }
                    userList.remove(getApp().getUser());

                    for (int k = 0; k < userList.size(); k++) {
                        sendMessage(userList.get(k), input);
                    }

                    Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                    customDialog.dismiss();
                }
            } else {

                for (int j = 0; j < getApp().getSelectedJourney().getHitchhikers().size(); j++) {
                    if (spinner.getSelectedItem().toString()
                            .equals(getApp().getSelectedJourney().getHitchhikers().get(j).getFullName())) {
                        mid = getApp().getSelectedJourney().getHitchhikers().get(j);
                    }
                }

                if (spinner.getSelectedItem().toString()
                        .equals(getApp().getSelectedJourney().getDriver().getFullName())) {
                    mid = getApp().getSelectedJourney().getDriver();
                }
                if (input.getText().toString().equals("")) {
                    input.setHint("Please fill in your message");
                    Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message",
                            Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                } else {
                    sendMessage(mid, input);
                    Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                    customDialog.dismiss();
                }

            }

        }

    });

    customDialog.show();

}

From source file:nf.frex.android.FrexActivity.java

private void preparePropertiesDialog(final Dialog dialog) {

    final Registry<Fractal> fractals = Registries.fractals;
    int fractalTypeIndex = fractals.getIndex(view.getFractalId());

    final Spinner fractalTypeSpinner = (Spinner) dialog.findViewById(R.id.fractal_type_spinner);
    final SeekBar iterationsSeekBar = (SeekBar) dialog.findViewById(R.id.num_iterations_seek_bar);
    final EditText iterationsEditText = (EditText) dialog.findViewById(R.id.num_iterations_edit_text);
    final CheckBox juliaModeCheckBox = (CheckBox) dialog.findViewById(R.id.julia_mode_fractal_check_box);
    final CheckBox decoratedFractal = (CheckBox) dialog.findViewById(R.id.decorated_fractal_check_box);
    final Button okButton = (Button) dialog.findViewById(R.id.ok_button);
    final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);

    juliaModeCheckBox.setEnabled(true);//from  w  ww  .  java  2  s .  c om

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            fractals.getIds());
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fractalTypeSpinner.setAdapter(arrayAdapter);
    fractalTypeSpinner.setSelection(fractalTypeIndex, true);
    fractalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) {
            Fractal fractal = fractals.getValue(position);
            iterationsEditText.setText(fractal.getDefaultIterMax() + "");
            boolean sameFractal = view.getFractalId().equals(fractals.getId(position));
            if (!sameFractal) {
                juliaModeCheckBox.setChecked(false);
            }
            juliaModeCheckBox.setEnabled(sameFractal);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    iterationsEditText.setText(view.getIterMax() + "", TextView.BufferType.NORMAL);

    final double iterationsMin = 1;
    final double iterationsMax = 3;
    final SeekBarConfigurer iterationsSeekBarConfigurer = SeekBarConfigurer.create(iterationsSeekBar,
            iterationsMin, iterationsMax, true, view.getIterMax());
    iterationsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                int iterMax = iterationsSeekBarConfigurer.getValueInt();
                iterationsEditText.setText(iterMax + "", TextView.BufferType.NORMAL);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    iterationsEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            try {
                int iterMax = Integer.parseInt(v.getText().toString());
                iterationsSeekBarConfigurer.setValue(iterMax);
                return true;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    decoratedFractal.setChecked(view.isDecoratedFractal());

    juliaModeCheckBox.setChecked(view.isJuliaModeFractal());

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int iterMax;
            try {
                iterMax = Integer.parseInt(iterationsEditText.getText().toString());
            } catch (NumberFormatException e) {
                Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()),
                        Toast.LENGTH_SHORT).show();
                return;
            }
            dialog.dismiss();
            String oldConfigName = view.getConfigName();
            String newFractalId = fractals.getId(fractalTypeSpinner.getSelectedItemPosition());
            Fractal fractal = fractals.getValue(fractalTypeSpinner.getSelectedItemPosition());
            String oldFractalId = view.getFractalId();
            boolean newJuliaModeFractal = juliaModeCheckBox.isChecked();
            boolean oldJuliaModeFractal = view.isJuliaModeFractal();
            view.setFractalId(newFractalId);
            view.setIterMax(iterMax);
            view.setDecoratedFractal(decoratedFractal.isChecked());
            view.setJuliaModeFractal(newJuliaModeFractal);
            boolean fractalTypeChanged = !oldFractalId.equals(newFractalId);
            if (fractalTypeChanged) {
                if (oldConfigName.contains(oldFractalId.toLowerCase())) {
                    view.setConfigName(newFractalId.toLowerCase());
                }
                view.setRegion(fractal.getDefaultRegion());
                view.setBailOut(fractal.getDefaultBailOut());
            }
            boolean juliaModeChanged = oldJuliaModeFractal != newJuliaModeFractal;
            if (fractalTypeChanged || juliaModeChanged) {
                view.getRegionHistory().clear();
                view.getRegionHistory().add(fractal.getDefaultRegion().clone());
            }
            view.recomputeAll();
        }
    });
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}

From source file:org.linphone.ContactEditorFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.inflater = inflater;

    contact = null;/*  ww  w  .j  a  v  a  2 s  . co m*/
    if (getArguments() != null) {
        if (getArguments().getSerializable("Contact") != null) {
            contact = (Contact) getArguments().getSerializable("Contact");
            isNewContact = false;
            contactID = Integer.parseInt(contact.getID());
            contact.refresh(getActivity().getContentResolver());
            if (getArguments().getString("NewSipAdress") != null) {
                newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
            }

        } else if (getArguments().getString("NewSipAdress") != null) {
            newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
            isNewContact = true;
        }
    }

    contactsManager = ContactsManager.getInstance();

    view = inflater.inflate(R.layout.contact_edit, container, false);

    deleteContact = (ImageView) view.findViewById(R.id.delete_contact);

    cancel = (ImageView) view.findViewById(R.id.cancel);
    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragmentManager().popBackStackImmediate();
        }
    });

    ok = (ImageView) view.findViewById(R.id.ok);
    ok.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isNewContact) {
                boolean areAllFielsEmpty = true;
                for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
                    if (nounoa.newNumberOrAddress != null && !nounoa.newNumberOrAddress.equals("")) {
                        areAllFielsEmpty = false;
                        break;
                    }
                }
                if (areAllFielsEmpty) {
                    getFragmentManager().popBackStackImmediate();
                    return;
                }
                contactsManager.createNewContact(ops, firstName.getText().toString(),
                        lastName.getText().toString());
                setContactPhoto();
            } else {
                contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(),
                        lastName.getText().toString());
                setContactPhoto();
            }

            for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
                numberOrAddress.save();
            }

            try {
                getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
                addLinphoneFriendIfNeeded();
                removeLinphoneTagIfNeeded();
                contactsManager.prepareContactsInBackground();
            } catch (Exception e) {
                e.printStackTrace();
            }

            getFragmentManager().popBackStackImmediate();

            if (LinphoneActivity.instance().getResources().getBoolean(R.bool.isTablet))
                ContactsListFragment.instance().invalidate();
        }
    });

    lastName = (EditText) view.findViewById(R.id.contactLastName);
    // Hack to display keyboard when touching focused edittext on Nexus One
    if (Version.sdkStrictlyBelow(Version.API11_HONEYCOMB_30)) {
        lastName.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
            }
        });
    }
    lastName.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (lastName.getText().length() > 0 || firstName.getText().length() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    firstName = (EditText) view.findViewById(R.id.contactFirstName);
    firstName.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (firstName.getText().length() > 0 || lastName.getText().length() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    if (!isNewContact) {
        String fn = findContactFirstName(String.valueOf(contactID));
        String ln = findContactLastName(String.valueOf(contactID));
        if (fn != null || ln != null) {
            firstName.setText(fn);
            lastName.setText(ln);
        } else {
            lastName.setText(contact.getName());
            firstName.setText("");
        }
        deleteContact.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Dialog dialog = LinphoneActivity.instance()
                        .displayDialog(getString(R.string.delete_text));
                Button delete = (Button) dialog.findViewById(R.id.delete_button);
                Button cancel = (Button) dialog.findViewById(R.id.cancel);

                delete.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        deleteExistingContact();
                        ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(),
                                contact);
                        LinphoneActivity.instance().displayContacts(false);
                        dialog.dismiss();
                    }
                });

                cancel.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();

                    }
                });
                dialog.show();
            }
        });
    } else {
        deleteContact.setVisibility(View.INVISIBLE);
    }

    contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
    if (contact != null && contact.getPhotoUri() != null) {
        InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(),
                contact.getID());
        contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {
        contactPicture.setImageResource(R.drawable.avatar);
    }

    contactPicture.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            pickImage();
        }
    });

    numbersAndAddresses = new ArrayList<NewOrUpdatedNumberOrAddress>();
    sipAddresses = initSipAddressFields(contact);
    numbers = initNumbersFields(contact);

    addSipAddress = (ImageView) view.findViewById(R.id.add_address_field);
    addSipAddress.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addEmptyRowToAllowNewNumberOrAddress(sipAddresses, true);
        }
    });

    addNumber = (ImageView) view.findViewById(R.id.add_number_field);
    addNumber.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addEmptyRowToAllowNewNumberOrAddress(numbers, false);
        }
    });

    ops = new ArrayList<ContentProviderOperation>();
    lastName.requestFocus();

    return view;
}