Example usage for android.view ViewGroup findViewWithTag

List of usage examples for android.view ViewGroup findViewWithTag

Introduction

In this page you can find the example usage for android.view ViewGroup 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:jp.wasabeef.blurry.Blurry.java

public static void delete(ViewGroup target) {
    View view = target.findViewWithTag(TAG);
    if (view != null) {
        target.removeView(view);//from   ww w.j a va  2  s . com
    }
}

From source file:com.example.android.animationsdemo.BoardFragment.java

public void addItem(View view) {

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View newCard = inflater.inflate(R.layout.new_card_layout, null, false);
    newCard.setTag("newCard");
    ViewGroup parentCol = (ViewGroup) view.getParent();
    ViewGroup svCol = (ViewGroup) parentCol.getChildAt(parentCol.getChildCount() - 1);
    ViewGroup containerCol = (ViewGroup) svCol.getChildAt(0);
    View check = containerCol.findViewWithTag("newCard");
    if (check == null)
        containerCol.addView(newCard, 0);
    else/*from  www .j a  v a 2 s  . c  o  m*/
        containerCol.removeView(check);
    ImageView save = (ImageView) newCard.findViewById(R.id.saveNewCard);
    final EditText title = (EditText) newCard.findViewById(R.id.newCardTitle);
    save.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view1) {
            if (isEmpty(title))
                Toast.makeText(context, "Please enter a title", Toast.LENGTH_SHORT).show();
            else {
                query = "";
                pager.getAdapter().notifyDataSetChanged();
                InputMethodManager imm = (InputMethodManager) context
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(title.getWindowToken(), 0);
            } //
        }
    });
}

From source file:com.shopify.buy.ui.ProductImagePagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    Context context = container.getContext();
    if (context != null) {
        View view = container.findViewWithTag(position);
        ImageView imageView = (ImageView) view.findViewById(R.id.image);
        Picasso.with(context).cancelRequest(imageView);
    }/*from w  w  w .  j a  va2s. co m*/
    super.destroyItem(container, position, object);
}

From source file:net.openwatch.acluaz.fragment.FormFragment.java

/**
 * Populate form given the db_id of an Incident in the database
 * This currently assumes that the database columns are equal to the view_tags (json keys)
 * @param container//from w  w  w. j  a  v a  2 s .  c o  m
 * @param db_id
 */
protected void fillFormFromDatabase(ViewGroup container, int db_id) {
    String TAG = "FormFragment-fillFormFromDatabase";
    Incident incident = Incident.objects(this.getActivity().getApplicationContext()).get(db_id);
    if (incident == null)
        return;
    ContentValues values = new ContentValues();
    try {
        incident.collectData(getActivity().getApplicationContext(), values, Incident.class);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Unable to collect ContentValues from Incident");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        Log.e(TAG, "Unable to collect ContentValues from Incident");
        e.printStackTrace();
    }

    View form_input;
    for (Entry<String, ?> entry : values.valueSet()) {

        if (entry.getKey().compareTo(getString(R.string.device_lat)) == 0
                || entry.getKey().compareTo(getString(R.string.device_lon)) == 0) {
            // Combine lat and lon into a Location and tag the gps toggle
            form_input = container.findViewById(R.id.gps_toggle);
            Location loc = new Location("db");
            loc.setLatitude(values.getAsDouble(DBConstants.DEVICE_LAT));
            loc.setLongitude(values.getAsDouble(DBConstants.DEVICE_LON));
            form_input.setTag(R.id.view_tag, loc);
        } else if (entry.getKey().compareTo(getString(R.string.date_tag)) == 0) {
            form_input = container.findViewById(R.id.date_input);
            if (form_input == null || entry.getValue() == null)
                continue;
            String date = (String) entry.getValue();
            try {
                ((EditText) form_input)
                        .setText(Constants.date_formatter.format(Constants.datetime_formatter.parse(date)));
                form_input = container.findViewById(R.id.time_input);
                if (form_input == null)
                    continue;
                ((EditText) form_input)
                        .setText(Constants.time_formatter.format(Constants.datetime_formatter.parse(date)));
            } catch (ParseException e) {
                Log.e(TAG, "Error setting date time form fields from database datetime");
                e.printStackTrace();
            }

        } else {
            // If the column value is simply bound to the view
            // with tag equal to column name...
            form_input = container.findViewWithTag(entry.getKey());
            setFormFieldValue(form_input, entry);
        }
    }

}