Example usage for android.view View findViewWithTag

List of usage examples for android.view View findViewWithTag

Introduction

In this page you can find the example usage for android.view View findViewWithTag.

Prototype

public final <T extends View> T findViewWithTag(Object tag) 

Source Link

Document

Look for a child view with the given tag.

Usage

From source file:org.adaway.ui.HostsSourcesFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info//www.  ja va2  s  . c  o m
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView urlTextView = (TextView) v.findViewWithTag("url_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_url_dialog, null);
    final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url);
    // set text from list
    inputEditText.setText(urlTextView.getText());
    inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    // move cursor to end of EditText
    Editable inputEditContent = inputEditText.getText();
    inputEditText.setSelection(inputEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String input = inputEditText.getText().toString();

                    if (RegexUtils.isValidUrl(input)) {
                        // update in db
                        ProviderHelper.updateHostsSourceUrl(mActivity, mCurrentRowId, input);
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_url_title);
                        alertDialog.setMessage(getString(org.adaway.R.string.no_url));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.adawaycn.ui.HostsSourcesFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/*  ww w.j  ava2s.  c o m*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView urlTextView = (TextView) v.findViewWithTag("url_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_url_dialog, null);
    final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url);
    // set text from list
    inputEditText.setText(urlTextView.getText());
    inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    // move cursor to end of EditText
    Editable inputEditContent = inputEditText.getText();
    inputEditText.setSelection(inputEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String input = inputEditText.getText().toString();

                    if (RegexUtils.isValidUrl(input)) {
                        // update in db
                        ProviderHelper.updateHostsSourceUrl(mActivity, mCurrentRowId, input);
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_url_title);
                        alertDialog.setMessage(getString(R.string.no_url));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:sssemil.com.hostsaway.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/* w  w w .j  a  v  a  2s . c om*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (RegexUtils.isValidHostname(hostname)) {
                        if (RegexUtils.isValidIP(ip)) {
                            ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId,
                                    hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.adaway.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info//w  w  w.j  av a 2 s.co  m
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (RegexUtils.isValidHostname(hostname)) {
                        if (RegexUtils.isValidIP(ip)) {
                            ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId,
                                    hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(org.adaway.R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(org.adaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.adawaycn.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info//from w ww.j a  v a 2s .co  m
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (org.adawaycn.util.RegexUtils.isValidHostname(hostname)) {
                        if (org.adawaycn.util.RegexUtils.isValidIP(ip)) {
                            org.adawaycn.provider.ProviderHelper.updateRedirectionListItemHostnameAndIp(
                                    mActivity, mCurrentRowId, hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java

public MBHeader getHeaderViewFromRoot(View root) {
    return ((MBHeader) root.findViewWithTag(Constants.C_PAGE_CONTENT_HEADER_VIEW));
}

From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java

public ScrollView getMainScrollViewFromRoot(View root) {
    if (_mainScrollView == null) {
        _mainScrollView = (ScrollView) root.findViewWithTag(Constants.C_PAGE_CONTENT_VIEW);
    }//ww w. j a v  a  2 s. c  om

    return _mainScrollView;
}

From source file:org.adaway.ui.BlacklistFragment.java

/**
 * Handle Checkboxes clicks here, because to enable context menus on longClick we had to disable
 * focusable and clickable on checkboxes in layout xml.
 *//*from w  ww.ja  va2s  .c o  m*/
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    mCurrentRowId = id;

    // Checkbox tags are defined by cursor position in HostsCursorAdapter, so we can get
    // checkboxes by position of cursor
    CheckBox cBox = (CheckBox) v.findViewWithTag(position);

    if (cBox != null) {
        if (cBox.isChecked()) {
            cBox.setChecked(false);
            // change status based on row id from cursor
            ProviderHelper.updateBlacklistItemEnabled(mActivity, mCurrentRowId, false);
        } else {
            cBox.setChecked(true);
            ProviderHelper.updateBlacklistItemEnabled(mActivity, mCurrentRowId, true);
        }
    } else {
        Log.e(Constants.TAG, "Checkbox could not be found!");
    }
}

From source file:org.adaway.ui.WhitelistFragment.java

/**
 * Handle Checkboxes clicks here, because to enable context menus on longClick we had to disable
 * focusable and clickable on checkboxes in layout xml.
 *//*from   www .  j  a v a 2  s  .  c o m*/
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    mCurrentRowId = id;

    // Checkbox tags are defined by cursor position in HostsCursorAdapter, so we can get
    // checkboxes by position of cursor
    CheckBox cBox = (CheckBox) v.findViewWithTag(position);

    if (cBox != null) {
        if (cBox.isChecked()) {
            cBox.setChecked(false);
            // change status based on row id from cursor
            ProviderHelper.updateWhitelistItemEnabled(mActivity, mCurrentRowId, false);
        } else {
            cBox.setChecked(true);
            ProviderHelper.updateWhitelistItemEnabled(mActivity, mCurrentRowId, true);
        }
    } else {
        Log.e(Constants.TAG, "Checkbox could not be found!");
    }
}

From source file:org.adawaycn.ui.BlacklistFragment.java

/**
 * Handle Checkboxes clicks here, because to enable context menus on longClick we had to disable
 * focusable and clickable on checkboxes in layout xml.
 *///from  w ww  . ja  v a 2  s.c o m
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    mCurrentRowId = id;

    // Checkbox tags are defined by cursor position in HostsCursorAdapter, so we can get
    // checkboxes by position of cursor
    CheckBox cBox = (CheckBox) v.findViewWithTag(position);

    if (cBox != null) {
        if (cBox.isChecked()) {
            cBox.setChecked(false);
            // change status based on row id from cursor
            org.adawaycn.provider.ProviderHelper.updateBlacklistItemEnabled(mActivity, mCurrentRowId, false);
        } else {
            cBox.setChecked(true);
            org.adawaycn.provider.ProviderHelper.updateBlacklistItemEnabled(mActivity, mCurrentRowId, true);
        }
    } else {
        org.adawaycn.util.Log.e(org.adawaycn.util.Constants.TAG, "Checkbox could not be found!");
    }
}