Java Code Examples for android.view.ViewGroup#setTag()

The following examples show how to use android.view.ViewGroup#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotSupportedRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public View getView(View convertView) {
    View view;
    TextHolder holder;

    if (convertView == null) {
        ViewGroup rowRoot = (ViewGroup) inflater.inflate(R.layout.listview_row_not_supported, null);
        TextView label = (TextView) rowRoot.findViewById(R.id.text_label);

        holder = new TextHolder(label);
        rowRoot.setTag(holder);
        view = rowRoot;
    } else {
        view = convertView;
        holder = (TextHolder) view.getTag();
    }

    RowCosmetics.setTextLabel(field, holder.textLabel);
    return view;
}
 
Example 2
Source File: Scene.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a Scene described by the resource file associated with the given
 * <code>layoutId</code> parameter. If such a Scene has already been created,
 * that same Scene will be returned. This caching of layoutId-based scenes enables
 * sharing of common scenes between those created in code and those referenced
 * by {@link TransitionManager} XML resource files.
 *
 * @param sceneRoot The root of the hierarchy in which scene changes
 *                  and transitions will take place.
 * @param layoutId  The id of a standard layout resource file.
 * @param context   The context used in the process of inflating
 *                  the layout resource.
 * @return
 */
@NonNull
public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, int layoutId, @NonNull Context context) {
    SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(R.id.scene_layoutid_cache);
    if (scenes == null) {
        scenes = new SparseArray<Scene>();
        sceneRoot.setTag(R.id.scene_layoutid_cache, scenes);
    }
    Scene scene = scenes.get(layoutId);
    if (scene != null) {
        return scene;
    } else {
        scene = new Scene(sceneRoot, layoutId, context);
        scenes.put(layoutId, scene);
        return scene;
    }
}
 
Example 3
Source File: ViewGroupAdapter.java    From MVVM-JueJin with MIT License 6 votes vote down vote up
/**
 * (伪)双向 databinding: 同 {@link RecyclerViewAdapter#setDataTwoWay(RecyclerView, ListVM, List)}
 *
 * @param container
 * @param vm
 * @param datas
 * @param <T>
 */
@BindingAdapter({"vm", "data"})
public static <T> void setDataTwoWay(final ViewGroup container, final ListVM<T> vm, List<T> datas){
    if(vm == null){
        return ;
    }
    bind(container, vm, datas);

    if(vm instanceof TwoWayListVM){
        boolean isInited = container.getTag(R.id.db_inited) != null;
        if(!isInited) {
            container.setTag(R.id.db_inited, true);
            loadData(container, (TwoWayListVM<T>)vm, null, null);
        }
    }
}
 
Example 4
Source File: RewardLayout.java    From RewardLayout with Apache License 2.0 6 votes vote down vote up
/**
 * 添加礼物到空闲的framelayout,在覆盖的时候可能存在礼物离场动画还么结束view还没有被remove的情况下
 * 根据该view的enable判断
 *
 * @param view
 */
private void addChildGift(View view) {
    for (int i = 0; i < getChildCount(); i++) {
        ViewGroup itemGroup = (ViewGroup) getChildAt(i);
        if (itemGroup.getChildCount() == 0) {
            itemGroup.addView(view);
            itemGroup.setTag(((GiftIdentify) view.getTag()).getTheLatestRefreshTime());
            break;
        } else {
            boolean isAllCancel = true;
            for (int j = 0; j < itemGroup.getChildCount(); j++) {
                if (itemGroup.getChildAt(j).isEnabled()) {
                    isAllCancel = false;
                    break;
                }
            }
            if (isAllCancel) {
                itemGroup.addView(view);
                itemGroup.setTag(((GiftIdentify) view.getTag()).getTheLatestRefreshTime());
                break;
            }
        }
    }
}
 
Example 5
Source File: NavDrawerFragment.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the profile header views. Reads the references to the child views and stores them
 * as tags
 */
private void initProfileHeaderViews() {

    //Get references to the two primary containers
    final ViewGroup profileContainer = (ViewGroup) mProfileHeader
            .findViewById(R.id.container_profile_info);
    mProfileHeader.setTag(R.id.container_profile_info, profileContainer);

    final ViewGroup signInContainer = (ViewGroup) mProfileHeader
            .findViewById(R.id.container_sign_in_message);
    mProfileHeader.setTag(R.id.container_sign_in_message, signInContainer);

    //Get references to the individual container children and set tags
    profileContainer
            .setTag(R.id.text_user_name, profileContainer.findViewById(R.id.text_user_name));
    profileContainer.setTag(R.id.image_user, profileContainer.findViewById(R.id.image_user));

    TextView textView = (TextView) signInContainer.findViewById(R.id.text_nav_item_title);
    textView.setText(R.string.text_sign_in);
    signInContainer.setTag(R.id.text_nav_item_title, textView);

}
 
Example 6
Source File: BackgroundPickers.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View view) {
    ImageView pickedView = (ImageView) view;
    ViewGroup pickerBox = (ViewGroup) view.getParent();

    // Clear old selection.
    for (int i = 0; i < pickerBox.getChildCount(); i++) {
        ImageView childView = (ImageView) pickerBox.getChildAt(i);
        childView.setBackgroundResource(R.drawable.unselected_background);
    }

    // Set new selection.
    pickedView.setBackgroundResource(R.drawable.selected_background);
    pickerBox.setTag(pickedView.getTag());

    if (listener != null) {
        listener.onBackgroundPickersChanged(BackgroundPickers.this);
    }
}
 
Example 7
Source File: ComplexItemLayoutAdapter.java    From MultiChoiceAdapter with Apache License 2.0 6 votes vote down vote up
@Override
protected View getViewImpl(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        int layout = R.layout.complex_item;
        LayoutInflater inflater = LayoutInflater.from(getContext());
        ViewGroup group = (ViewGroup) inflater.inflate(layout, parent, false);
        convertView = group;
        viewHolder = new ViewHolder();
        viewHolder.nameTextView = (TextView) group.findViewById(R.id.fName1);
        viewHolder.progressBar = (ProgressBar) group.findViewById(R.id.lp1);
        group.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    String country = getItem(position);
    viewHolder.nameTextView.setText(country);
    viewHolder.progressBar.setProgress(random.nextInt(100));
    return convertView;
}
 
Example 8
Source File: LongTextRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public View getView(View convertView) {
    View view;
    EditTextHolder holder;
    
    if (convertView == null) {
        ViewGroup rowRoot = (ViewGroup) inflater.inflate(R.layout.listview_row_long_text, null);
        TextView label = (TextView) rowRoot.findViewById(R.id.text_label);
        EditText editText = (EditText) rowRoot.findViewById(R.id.edit_long_text_row);
       
        EditTextWatcher watcher = new EditTextWatcher(field);
        editText.addTextChangedListener(watcher);
        
        holder = new EditTextHolder(label, editText, watcher);
        rowRoot.setTag(holder);
        view = rowRoot;
    } else {
        view = convertView;
        holder = (EditTextHolder) view.getTag();
    }

    RowCosmetics.setTextLabel(field, holder.textLabel);
    
    holder.textWatcher.setField(field);
    holder.editText.addTextChangedListener(holder.textWatcher);
    holder.editText.setText(field.getValue());
    holder.editText.clearFocus(); 

    if(readOnly){
        holder.editText.setEnabled(false);
    } else {
        holder.editText.setEnabled(true);
    }
    return view;
}
 
Example 9
Source File: IntegerRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public View getView(View convertView) {
    View view;
    EditTextHolder holder;
    
    if (convertView == null) {
        ViewGroup rowRoot = (ViewGroup) inflater.inflate(R.layout.listview_row_integer, null);
        TextView label = (TextView) rowRoot.findViewById(R.id.text_label);
        EditText editText = (EditText) rowRoot.findViewById(R.id.edit_integer_row);
       
        EditTextWatcher watcher = new EditTextWatcher(field);
        editText.addTextChangedListener(watcher);
        
        holder = new EditTextHolder(label, editText, watcher);
        rowRoot.setTag(holder);
        view = rowRoot;
    } else {
        view = convertView;
        holder = (EditTextHolder) view.getTag();
    }

    RowCosmetics.setTextLabel(field, holder.textLabel);
    
    holder.textWatcher.setField(field);
    holder.editText.addTextChangedListener(holder.textWatcher);
    holder.editText.setText(field.getValue());
    holder.editText.clearFocus();
    holder.editText.setOnEditorActionListener(mOnEditorActionListener);

    if(readOnly){
        holder.editText.setEnabled(false);
    } else {
        holder.editText.setEnabled(true);
    }
    return view;
}
 
Example 10
Source File: Plugin.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
public void destroy() {
    this.mOnLoadFinishs.clear();

    if (mWebView != null) {
        ViewGroup contentView = (ViewGroup) mWebView.getRootView().findViewById(android.R.id.content);
        contentView.setTag(ID_PLUGIN, null);
        contentView.removeView(mRootLayout);
        mRootLayout.removeView(mWebView);
        mWebView.destroy();
        mRootLayout = null;
        mWebView = null;
    }
}
 
Example 11
Source File: TextRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public View getView(View convertView) {
    View view;
    EditTextHolder holder;

    if (convertView == null) {
        ViewGroup rowRoot = (ViewGroup) inflater.inflate(R.layout.listview_row_text, null);
        TextView label = (TextView) rowRoot.findViewById(R.id.text_label);
        EditText editText = (EditText) rowRoot.findViewById(R.id.edit_text_row);

        EditTextWatcher watcher = new EditTextWatcher(field);
        editText.addTextChangedListener(watcher);

        holder = new EditTextHolder(label, editText, watcher);
        rowRoot.setTag(holder);
        view = rowRoot;
    } else {
        view = convertView;
        holder = (EditTextHolder) view.getTag();
    }

    RowCosmetics.setTextLabel(field, holder.textLabel);
    
    holder.textWatcher.setField(field);
    holder.editText.addTextChangedListener(holder.textWatcher);
    holder.editText.setText(field.getValue());
    holder.editText.clearFocus();
    holder.editText.setOnEditorActionListener(mOnEditorActionListener);

    if(readOnly){
        holder.editText.setEnabled(false);
    } else {
        holder.editText.setEnabled(true);
    }
    return view;
}
 
Example 12
Source File: MediaDetailPresenter.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public Object instantiateItem(ViewGroup container, int position) {
    MediaModel mediaModel = (MediaModel) this.modelList.get(position);
    View view = LayoutInflater.from(this.mMediaActivity.getApplicationContext()).inflate(R.layout.album_adapter_detail_item, container, false);
    MediaDetialViewHolder viewHolder = new MediaDetialViewHolder(view);
    container.setTag(viewHolder);
    this.cacheContainer = container;
    initItemData(viewHolder, position, mediaModel);
    container.addView(view);
    return view;
}
 
Example 13
Source File: ExpandableListItemAdapter.java    From ListViewAnimations with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
    ViewGroup view = (ViewGroup) convertView;
    ViewHolder viewHolder;

    if (view == null) {
        view = createView(parent);

        viewHolder = new ViewHolder();
        viewHolder.titleParent = (ViewGroup) view.findViewById(mTitleParentResId);
        viewHolder.contentParent = (ViewGroup) view.findViewById(mContentParentResId);

        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    View titleView = getTitleView(position, viewHolder.titleView, viewHolder.titleParent);
    if (!titleView.equals(viewHolder.titleView)) {
        viewHolder.titleParent.removeAllViews();
        viewHolder.titleParent.addView(titleView);

        if (mActionViewResId == 0) {
            view.setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        } else {
            view.findViewById(mActionViewResId).setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        }
    }
    viewHolder.titleView = titleView;

    View contentView = getContentView(position, viewHolder.contentView, viewHolder.contentParent);
    if (!contentView.equals(viewHolder.contentView)) {
        viewHolder.contentParent.removeAllViews();
        viewHolder.contentParent.addView(contentView);
    }
    viewHolder.contentView = contentView;

    viewHolder.contentParent.setVisibility(mExpandedIds.contains(getItemId(position)) ? View.VISIBLE : View.GONE);
    viewHolder.contentParent.setTag(getItemId(position));

    LayoutParams layoutParams = viewHolder.contentParent.getLayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    viewHolder.contentParent.setLayoutParams(layoutParams);

    return view;
}
 
Example 14
Source File: ExpandableListItemAdapter.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    ViewGroup view = (ViewGroup) convertView;
    ViewHolder viewHolder;

    if (view == null) {
        view = createView(parent);

        viewHolder = new ViewHolder();
        viewHolder.titleParent = (ViewGroup) view.findViewById(mTitleParentResId);
        viewHolder.contentParent = (ViewGroup) view.findViewById(mContentParentResId);

        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    View titleView = getTitleView(position, viewHolder.titleView, viewHolder.titleParent);
    if (titleView != viewHolder.titleView) {
        viewHolder.titleParent.removeAllViews();
        viewHolder.titleParent.addView(titleView);

        if (mActionViewResId == 0) {
            view.setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        } else {
            view.findViewById(mActionViewResId).setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        }
    }
    viewHolder.titleView = titleView;

    View contentView = getContentView(position, viewHolder.contentView, viewHolder.contentParent);
    if (contentView != viewHolder.contentView) {
        viewHolder.contentParent.removeAllViews();
        viewHolder.contentParent.addView(contentView);
    }
    viewHolder.contentView = contentView;

    viewHolder.contentParent.setVisibility(mExpandedIds.contains(getItemId(position)) ? View.VISIBLE : View.GONE);
    viewHolder.contentParent.setTag(getItemId(position));

    LayoutParams layoutParams = viewHolder.contentParent.getLayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    viewHolder.contentParent.setLayoutParams(layoutParams);

    return view;
}
 
Example 15
Source File: ExpandableListItemAdapter.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    ViewGroup view = (ViewGroup) convertView;
    ViewHolder viewHolder;

    if (view == null) {
        view = createView(parent);

        viewHolder = new ViewHolder();
        viewHolder.titleParent = (ViewGroup) view.findViewById(mTitleParentResId);
        viewHolder.contentParent = (ViewGroup) view.findViewById(mContentParentResId);

        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    View titleView = getTitleView(position, viewHolder.titleView, viewHolder.titleParent);
    if (titleView != viewHolder.titleView) {
        viewHolder.titleParent.removeAllViews();
        viewHolder.titleParent.addView(titleView);

        if (mActionViewResId == 0) {
            view.setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        } else {
            view.findViewById(mActionViewResId).setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        }
    }
    viewHolder.titleView = titleView;

    View contentView = getContentView(position, viewHolder.contentView, viewHolder.contentParent);
    if (contentView != viewHolder.contentView) {
        viewHolder.contentParent.removeAllViews();
        viewHolder.contentParent.addView(contentView);
    }
    viewHolder.contentView = contentView;

    viewHolder.contentParent.setVisibility(mExpandedIds.contains(getItemId(position)) ? View.VISIBLE : View.GONE);
    viewHolder.contentParent.setTag(getItemId(position));

    LayoutParams layoutParams = viewHolder.contentParent.getLayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    viewHolder.contentParent.setLayoutParams(layoutParams);

    return view;
}
 
Example 16
Source File: ViewHolder.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
ViewGroup inflateVideoView(ViewGroup container) {
    ViewGroup v = ItemViewUtil.inflateVideoView(container);
    v.setTag(albumItem.getPath());
    this.itemView = v;
    return v;
}
 
Example 17
Source File: ExpandableListItemAdapter.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    ViewGroup view = (ViewGroup) convertView;
    ViewHolder viewHolder;

    if (view == null) {
        view = createView(parent);

        viewHolder = new ViewHolder();
        viewHolder.titleParent = (ViewGroup) view.findViewById(mTitleParentResId);
        viewHolder.contentParent = (ViewGroup) view.findViewById(mContentParentResId);

        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    View titleView = getTitleView(position, viewHolder.titleView, viewHolder.titleParent);
    if (titleView != viewHolder.titleView) {
        viewHolder.titleParent.removeAllViews();
        viewHolder.titleParent.addView(titleView);

        if (mActionViewResId == 0) {
            view.setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        } else {
            view.findViewById(mActionViewResId).setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        }
    }
    viewHolder.titleView = titleView;

    View contentView = getContentView(position, viewHolder.contentView, viewHolder.contentParent);
    if (contentView != viewHolder.contentView) {
        viewHolder.contentParent.removeAllViews();
        viewHolder.contentParent.addView(contentView);
    }
    viewHolder.contentView = contentView;

    viewHolder.contentParent.setVisibility(mExpandedIds.contains(getItemId(position)) ? View.VISIBLE : View.GONE);
    viewHolder.contentParent.setTag(getItemId(position));

    ViewGroup.LayoutParams layoutParams = viewHolder.contentParent.getLayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    viewHolder.contentParent.setLayoutParams(layoutParams);

    return view;
}
 
Example 18
Source File: StatusBarCompat.java    From LeisureRead with Apache License 2.0 4 votes vote down vote up
/**
 * change to full screen mode
 *
 * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it
 */
public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {

  Window window = activity.getWindow();
  ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);

  //set child View not fill the system window
  View mChildView = mContentView.getChildAt(0);
  if (mChildView != null) {
    ViewCompat.setFitsSystemWindows(mChildView, false);
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    int statusBarHeight = getStatusBarHeight(activity);

    //First translucent status bar.
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      //After LOLLIPOP just set LayoutParams.
      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      if (hideStatusBarBackground) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(COLOR_TRANSLUCENT);
      } else {
        window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA));
      }
      //must call requestApplyInsets, otherwise it will have space in screen bottom
      if (mChildView != null) {
        ViewCompat.requestApplyInsets(mChildView);
      }
    } else {
      ViewGroup mDecorView = (ViewGroup) window.getDecorView();
      if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean &&
          (Boolean) mDecorView.getTag()) {
        mChildView = mDecorView.getChildAt(0);
        //remove fake status bar view.
        mContentView.removeView(mChildView);
        mChildView = mContentView.getChildAt(0);
        if (mChildView != null) {
          FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();
          //cancel the margin top
          if (lp != null && lp.topMargin >= statusBarHeight) {
            lp.topMargin -= statusBarHeight;
            mChildView.setLayoutParams(lp);
          }
        }
        mDecorView.setTag(false);
      }
    }
  }
}
 
Example 19
Source File: ThemedActivity.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setTranslucentStatusBar() {
    Window window = getWindow();
    ViewGroup mContentView = findViewById(Window.ID_ANDROID_CONTENT);
    // set child View not fill the system window
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
        mChildView.setFitsSystemWindows(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int statusBarHeight = ViewUtils.getStatusBarHeight(this);
        // First translucent status bar.
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // After LOLLIPOP just set LayoutParams.
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(Color.TRANSPARENT);
            // must call requestApplyInsets, otherwise it will have space in screen bottom
            if (mChildView != null) {
                ViewCompat.requestApplyInsets(mChildView);
            }
        } else {
            ViewGroup mDecorView = (ViewGroup) window.getDecorView();
            if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean)mDecorView.getTag()) {
                mChildView = mDecorView.getChildAt(0);
                // remove fake status bar view.
                mContentView.removeView(mChildView);
                mChildView = mContentView.getChildAt(0);
                if (mChildView != null) {
                    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();
                    // cancel the margin top
                    if (lp != null && lp.topMargin >= statusBarHeight) {
                        lp.topMargin -= statusBarHeight;
                        mChildView.setLayoutParams(lp);
                    }
                }
                mDecorView.setTag(false);
            }
        }
    }
}
 
Example 20
Source File: GenderRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public View getView(View convertView) {
	View view;
	BooleanRowHolder holder;

	if (convertView == null) {
		ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.listview_row_gender, null);
		TextView label = (TextView) rootView.findViewById(R.id.text_label);

		MaleButtonListener mListener = new MaleButtonListener(field);
		FemaleButtonListener fListener = new FemaleButtonListener(field);
		OtherButtonListener oListener = new OtherButtonListener(field);

		CompoundButton mButton = (CompoundButton) rootView.findViewById(R.id.option_male);
		CompoundButton fButton = (CompoundButton) rootView.findViewById(R.id.option_female);
		CompoundButton oButton = (CompoundButton) rootView.findViewById(R.id.option_other);

		mButton.setOnCheckedChangeListener(mListener);
		fButton.setOnCheckedChangeListener(fListener);
		oButton.setOnCheckedChangeListener(oListener);

		holder = new BooleanRowHolder(label, mListener, fListener, oListener, mButton, fButton,
				oButton);

		rootView.setTag(holder);
		view = rootView;
	} else {
		view = convertView;
		holder = (BooleanRowHolder) convertView.getTag();
	}

	RowCosmetics.setTextLabel(field, holder.textLabel);

	holder.optionMaleListener.setField(field);
	holder.optionFemaleListener.setField(field);
	holder.optionOtherListener.setField(field);

	holder.optionMale.setOnCheckedChangeListener(holder.optionMaleListener);
	holder.optionFemale.setOnCheckedChangeListener(holder.optionFemaleListener);
	holder.optionOther.setOnCheckedChangeListener(holder.optionOtherListener);

	if (field.getValue().equals(MALE))
		holder.optionMale.setChecked(true);
	else if (field.getValue().equals(FEMALE))
		holder.optionFemale.setChecked(true);
	else if (field.getValue().equals(OTHER))
		holder.optionOther.setChecked(true);

	if(readOnly){
		holder.optionOther.setEnabled(false);
		holder.optionFemale.setEnabled(false);
		holder.optionMale.setEnabled(false);
	} else {
		holder.optionOther.setEnabled(true);
		holder.optionFemale.setEnabled(true);
		holder.optionMale.setEnabled(true);
	}
	return view;
}