Example usage for android.widget AdapterView setTag

List of usage examples for android.widget AdapterView setTag

Introduction

In this page you can find the example usage for android.widget AdapterView setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:de.uni_koblenz_landau.apow.PatientDetailEditFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

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

    // Create UI references.
    mBirthDateDialog = (DateDialogFragment) getFragmentManager().findFragmentByTag(BIRTHDATE_DIALOG_ID);
    if (mBirthDateDialog != null) {
        mBirthDateDialog.setListener(this);
    }/*  w ww.  j av a  2 s .co  m*/
    mDeathDateDialog = (DateDialogFragment) getFragmentManager().findFragmentByTag(DEATHDATE_DIALOG_ID);
    if (mDeathDateDialog != null) {
        mDeathDateDialog.setListener(this);
    }

    mIdentifierView = (EditText) view.findViewById(R.id.patient_detail_edit_identifier);
    mNamePrefixView = (EditText) view.findViewById(R.id.patient_detail_edit_name_prefix);
    mGivenNameView = (EditText) view.findViewById(R.id.patient_detail_edit_name_given_name);
    mMiddleNameView = (EditText) view.findViewById(R.id.patient_detail_edit_name_middle_name);
    mFamilyNamePrefixView = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name_prefix);
    mFamilyNameView = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name);
    mFamilyName2View = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name2);
    mFamilyNameSuffixView = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name_suffix);
    mDegreeView = (EditText) view.findViewById(R.id.patient_detail_edit_name_degree);
    mGenderView = (Spinner) view.findViewById(R.id.patient_detail_edit_gender);
    mBirthdateView = (TextView) view.findViewById(R.id.patient_detail_edit_birthdate);
    mBirthdateEstimatedView = (CheckBox) view.findViewById(R.id.patient_detail_edit_birthdate_estimated);
    mAddress1View = (EditText) view.findViewById(R.id.patient_detail_edit_address_address1);
    mAddress2View = (EditText) view.findViewById(R.id.patient_detail_edit_address_address2);
    mCityVillageView = (EditText) view.findViewById(R.id.patient_detail_edit_address_cityvillage);
    mDistrictsView = (Spinner) view.findViewById(R.id.patient_detail_edit_address_district);
    mRegionsView = (Spinner) view.findViewById(R.id.patient_detail_edit_address_region);
    mRegionsView.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
            Region region = (Region) parent.getItemAtPosition(pos);
            ArrayAdapter<District> adapter = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, region.getDistricts());
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mDistrictsView.setAdapter(adapter);

            if (parent.getTag() != null) {
                mDistrictsView.setSelection((int) parent.getTag());
                parent.setTag(null);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mCountryView = (EditText) view.findViewById(R.id.patient_detail_edit_address_country);
    mLongitudeView = (EditText) view.findViewById(R.id.patient_detail_edit_address_longitude);
    mLatitudeView = (EditText) view.findViewById(R.id.patient_detail_edit_address_latitude);
    mDeathdateView = (TextView) view.findViewById(R.id.patient_detail_edit_deathdate);
    mDeadLayout = (LinearLayout) view.findViewById(R.id.patient_detail_edit_dead_group);

    mDeadLayout = (LinearLayout) view.findViewById(R.id.patient_detail_edit_dead_group);
    mDeadView = (CheckBox) view.findViewById(R.id.patient_detail_edit_dead);
    mDeadView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            CheckBox dead = (CheckBox) v;
            if (dead.isChecked()) {
                mDeadLayout.setVisibility(View.VISIBLE);
            } else {
                mDeadLayout.setVisibility(View.GONE);
            }
        }
    });

    // Restore UI from saved instance or load data.
    if (savedInstanceState != null) {
        mPatient = (Patient) savedInstanceState.getSerializable(ARG_PATIENT);
        if (mPatient != null) {
            mRegions = (List<Region>) savedInstanceState.getSerializable(ARG_REGIONS);
            ArrayAdapter<Region> adapter = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, mRegions);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mRegionsView.setAdapter(adapter);
            ArrayAdapter<District> adapter1 = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, mRegions.get(0).getDistricts());
            adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mDistrictsView.setAdapter(adapter1);

            String selectedRegion = savedInstanceState.getString(ARG_SELECTED_REGION);
            String selectedDistrict = savedInstanceState.getString(ARG_SELECTED_DISTRICT);
            for (int i = 0; i < adapter.getCount(); i++) {
                Region region = adapter.getItem(i);
                if (region.getRegionName().equals(selectedRegion)) {
                    for (int j = 0; j < region.getDistricts().size(); j++) {
                        if (region.getDistricts().get(j).getDistrictName().equals(selectedDistrict)) {
                            mRegionsView.setTag(j);
                            mRegionsView.setSelection(i, false);
                            adapter1 = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item,
                                    region.getDistricts());
                            adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                            mDistrictsView.setAdapter(adapter1);
                            mDistrictsView.setSelection(j, false);
                            break;
                        }
                    }
                    break;
                }
            }

            if (savedInstanceState.getBoolean(ARG_DEAD)) {
                mDeadLayout.setVisibility(View.VISIBLE);
            } else {
                mDeadLayout.setVisibility(View.GONE);
            }
        }
    } else {
        loadPatient();
    }

    return view;
}

From source file:com.xandy.calendar.EventInfoFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mReminderChangeListener = new OnItemSelectedListener() {
        @Override/*ww  w .  j av  a2  s. c o  m*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Integer prevValue = (Integer) parent.getTag();
            if (prevValue == null || prevValue != position) {
                parent.setTag(position);
                mUserModifiedReminders = true;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // do nothing
        }

    };

    if (savedInstanceState != null) {
        mIsDialog = savedInstanceState.getBoolean(BUNDLE_KEY_IS_DIALOG, false);
        mWindowStyle = savedInstanceState.getInt(BUNDLE_KEY_WINDOW_STYLE, DIALOG_WINDOW_STYLE);
    }

    if (mIsDialog) {
        applyDialogParams();
    }

    final Activity activity = getActivity();
    mContext = activity;
    mColorPickerDialog = (EventColorPickerDialog) getActivity().getSupportFragmentManager()
            .findFragmentByTag(COLOR_PICKER_DIALOG_TAG);
    if (mColorPickerDialog != null) {
        mColorPickerDialog.setOnColorSelectedListener(this);
    }
}

From source file:com.android.calendar.EventInfoFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mReminderChangeListener = new OnItemSelectedListener() {
        @Override/*from  ww w.j a v a 2  s.c o  m*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Integer prevValue = (Integer) parent.getTag();
            if (prevValue == null || prevValue != position) {
                parent.setTag(position);
                mUserModifiedReminders = true;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // do nothing
        }

    };

    if (savedInstanceState != null) {
        mIsDialog = savedInstanceState.getBoolean(BUNDLE_KEY_IS_DIALOG, false);
        mWindowStyle = savedInstanceState.getInt(BUNDLE_KEY_WINDOW_STYLE, DIALOG_WINDOW_STYLE);
    }

    if (mIsDialog) {
        applyDialogParams();
    }

    final FragmentActivity activity = getActivity();
    mContext = activity;
    mColorPickerDialog = (EventColorPickerDialog) activity.getSupportFragmentManager()
            .findFragmentByTag(COLOR_PICKER_DIALOG_TAG);
    if (mColorPickerDialog != null) {
        mColorPickerDialog.setOnColorSelectedListener(this);
    }
}