Java Code Examples for android.view.View.setId()

The following are Jave code examples for showing how to use setId() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ToggleButtons   File: ToggleGroup.java   Source Code and License Vote up 7 votes
/**
 * {@inheritDoc}
 */
public void onChildViewAdded(View parent, View child) {
    if (parent == ToggleGroup.this && child instanceof CompoundButton) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
         if (Build.VERSION.SDK_INT < 17)
          id = child.hashCode();
         else
             id = View.generateViewId();
            child.setId(id);
        }
        ((CompoundButton) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 2
Project: SetupWizardLibCompat   File: Item.java   Source Code and License Vote up 7 votes
@Override
public void onBindView(View view) {
    TextView label = (TextView) view.findViewById(R.id.suw_items_title);
    label.setText(getTitle());

    TextView summaryView = (TextView) view.findViewById(R.id.suw_items_summary);
    CharSequence summary = getSummary();
    if (summary != null && summary.length() > 0) {
        summaryView.setText(summary);
        summaryView.setVisibility(View.VISIBLE);
    } else {
        summaryView.setVisibility(View.GONE);
    }

    final View iconContainer = view.findViewById(R.id.suw_items_icon_container);
    final Drawable icon = getIcon();
    if (icon != null) {
        final ImageView iconView = (ImageView) view.findViewById(R.id.suw_items_icon);
        // Set the image drawable to null before setting the state and level to avoid affecting
        // any recycled drawable in the ImageView
        iconView.setImageDrawable(null);
        iconView.setImageState(icon.getState(), false /* merge */);
        iconView.setImageLevel(icon.getLevel());
        iconView.setImageDrawable(icon);
        iconContainer.setVisibility(View.VISIBLE);
    } else {
        iconContainer.setVisibility(View.GONE);
    }

    view.setId(getViewId());
}
 
Example 3
Project: ChatKeyboard-master   File: EmoticonsToolBarView.java   Source Code and License Vote up 6 votes
public void addFixedView(View view, boolean isRight) {
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    LayoutParams hsvParams = (LayoutParams) hsv_toolbar.getLayoutParams();
    if (view.getId() <= 0) {
        view.setId(getIdValue());
    }
    if (isRight) {
        params.addRule(ALIGN_PARENT_RIGHT);
        hsvParams.addRule(LEFT_OF, view.getId());
    } else {
        params.addRule(ALIGN_PARENT_LEFT);
        hsvParams.addRule(RIGHT_OF, view.getId());
    }
    addView(view, params);
    hsv_toolbar.setLayoutParams(hsvParams);
}
 
Example 4
Project: memento-app   File: PersonActivity.java   Source Code and License Vote up 6 votes
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // set the item view
    if (convertView == null) {
        LayoutInflater layoutInflater
                = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(
                R.layout.item_face_with_checkbox, parent, false);
    }
    convertView.setId(position);

    Uri uri = Uri.parse(StorageHelper.getFaceUri(
            faceIdList.get(position), PersonActivity.this));
    ((ImageView)convertView.findViewById(R.id.image_face)).setImageURI(uri);

    // set the checked status of the item
    CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkbox_face);
    if (longPressed) {
        checkBox.setVisibility(View.VISIBLE);

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                faceChecked.set(position, isChecked);
            }
        });
        checkBox.setChecked(faceChecked.get(position));
    } else {
        checkBox.setVisibility(View.INVISIBLE);
    }

    return convertView;
}
 
Example 5
Project: GitHub   File: EmoticonsToolBarView.java   Source Code and License Vote up 6 votes
public void addFixedToolItemView(boolean isRight, int rec, final PageSetEntity pageSetEntity, OnClickListener onClickListener) {
    View toolBtnView = getCommonItemToolBtn();
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    LayoutParams hsvParams = (LayoutParams) hsv_toolbar.getLayoutParams();
    if (toolBtnView.getId() <= 0) {
        toolBtnView.setId(isRight ? R.id.id_toolbar_right : R.id.id_toolbar_left);
    }
    if (isRight) {
        params.addRule(ALIGN_PARENT_RIGHT);
        hsvParams.addRule(LEFT_OF, toolBtnView.getId());
    } else {
        params.addRule(ALIGN_PARENT_LEFT);
        hsvParams.addRule(RIGHT_OF, toolBtnView.getId());
    }
    addView(toolBtnView, params);
    hsv_toolbar.setLayoutParams(hsvParams);
    initItemToolBtn(toolBtnView, rec, pageSetEntity, onClickListener);
}
 
Example 6
Project: GitHub   File: FloatOnKeyboardLayout.java   Source Code and License Vote up 6 votes
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    int childSum = this.getChildCount();
    if(childSum > 1) {
        throw new IllegalStateException("can host only one direct child");
    } else {
        super.addView(child, index, params);
        android.widget.RelativeLayout.LayoutParams paramsChild;
        if(childSum == 0) {
            if(child.getId() < 0) {
                child.setId(ID_CHILD);
            }

            paramsChild = (android.widget.RelativeLayout.LayoutParams)child.getLayoutParams();
            paramsChild.addRule(12);
            child.setLayoutParams(paramsChild);
        } else if(childSum == 1) {
            paramsChild = (android.widget.RelativeLayout.LayoutParams)child.getLayoutParams();
            paramsChild.addRule(2, ID_CHILD);
            child.setLayoutParams(paramsChild);
        }

    }
}
 
Example 7
Project: EasyEmoji   File: IMERootLayout.java   Source Code and License Vote up 6 votes
public void addPanelLayout(View panel){
    ViewGroup contentLayout = (ViewGroup) ((Activity)mContext).findViewById(android.R.id.content);
    View customRootView = contentLayout.getChildAt(0);
    contentLayout.removeView(customRootView);
    contentLayout.addView(this);

    panel.setId(R.id.panel_container);
    LayoutParams customRootParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    customRootParams.addRule(RelativeLayout.ABOVE,panel.getId());
    customRootView.setLayoutParams(customRootParams);

    LayoutParams panelParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0);
    panelParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    panel.setLayoutParams(panelParams);
    addView(panel);
    addView(customRootView);
    mPanelManager.closePanel();
}
 
Example 8
Project: LaunchEnr   File: CellLayout.java   Source Code and License Vote up 6 votes
public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params,
        boolean markCells) {
    final LayoutParams lp = params;

    // Hotseat icons - remove text
    if (child instanceof BubbleTextView) {
        BubbleTextView bubbleChild = (BubbleTextView) child;
        bubbleChild.setTextVisibility(mContainerType != HOTSEAT);
    }

    child.setScaleX(mChildScale);
    child.setScaleY(mChildScale);

    // Generate an id for each view, this assumes we have at most 256x256 cells
    // per workspace screen
    if (lp.cellX >= 0 && lp.cellX <= mCountX - 1 && lp.cellY >= 0 && lp.cellY <= mCountY - 1) {
        // If the horizontal or vertical span is set to -1, it is taken to
        // mean that it spans the extent of the CellLayout
        if (lp.cellHSpan < 0) lp.cellHSpan = mCountX;
        if (lp.cellVSpan < 0) lp.cellVSpan = mCountY;

        child.setId(childId);
        mShortcutsAndWidgets.addView(child, index, lp);

        if (markCells) markCellsAsOccupiedForView(child);

        return true;
    }
    return false;
}
 
Example 9
Project: SetupWizardLibCompat   File: ButtonBarItem.java   Source Code and License Vote up 6 votes
@Override
public void onBindView(View view) {
    // Note: The efficiency could be improved by trying to recycle the buttons created by
    // ButtonItem
    final LinearLayout layout = (LinearLayout) view;
    layout.removeAllViews();

    for (ButtonItem buttonItem : mButtons) {
        Button button = buttonItem.createButton(layout);
        layout.addView(button);
    }

    view.setId(getViewId());
}
 
Example 10
Project: memento-app   File: LogActivity.java   Source Code and License Vote up 6 votes
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater layoutInflater =
                (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.item_log, parent, false);
    }
    convertView.setId(position);

    ((TextView)convertView.findViewById(R.id.log)).setText(log.get(position));

    return convertView;
}
 
Example 11
Project: LuaViewPlayground   File: LuaViewUtil.java   Source Code and License Vote up 6 votes
/**
 * set id
 *
 * @param view
 */
public static void setId(View view) {
    if (view != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            try {//samsung SM-N9009(4.3) crash here, so protected
                view.setId(View.generateViewId());
            } catch (Exception e) {
                view.setId(generateViewId());
            }
        } else {
            view.setId(generateViewId());
        }
    }
}
 
Example 12
Project: From-design-to-Android-part1   File: OrderDialogFragment.java   Source Code and License Vote up 6 votes
private View getTargetView(View v) {
    final String resourceName = getResources().getResourceEntryName(v.getId());

    if (resourceName.startsWith(ID_SIZE_SUFFIX) ||
        resourceName.startsWith(ID_DATE_SUFFIX)) {
        v.setId(R.id.first_position);
        return binding.txtLabelSize;

    } else if (resourceName.startsWith(ID_COLOR_SUFFIX) ||
        resourceName.startsWith(ID_TIME_SUFFIX)) {
        v.setId(R.id.second_position);
        return binding.txtLabelColour;
    }

    throw new IllegalStateException();
}
 
Example 13
Project: VRPlayer   File: StatusBarUtil.java   Source Code and License Vote up 6 votes
/**
 * 生成一个和状态栏大小相同的半透明矩形条
 *
 * @param activity 需要设置的activity
 * @param color    状态栏颜色值
 * @param alpha    透明值
 * @return 状态栏矩形条
 */
private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
    // 绘制一个和状态栏一样高的矩形
    View statusBarView = new View(activity);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
    statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
    return statusBarView;
}
 
Example 14
Project: MaterialAbout   File: AboutView.java   Source Code and License Vote up 6 votes
private View addItem(ViewGroup holder, int layout, Item item) {
    View view = layoutInflater.inflate(layout, null);
    view.setId(item.getId());

    TextView tvLabel = (TextView) view.findViewById(R.id.label);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.icon);

    Icon.on(ivIcon).bitmap(item.getIcon()).color(getIconColor()).put();

    tvLabel.setText(item.getLabel());
    view.setOnClickListener(item.getOnClick());

    RippleUtil.backgroundRipple(view, getCardColor());

    holder.addView(view);
    return view;
}
 
Example 15
Project: qmui   File: QMUITopBar.java   Source Code and License Vote up 6 votes
/**
 * 在 TopBar 的右侧添加 View,如果此前已经有 View 通过该方法添加到 TopBar,则新添加进去的 View 会出现在已有View的左侧
 *
 * @param view         要添加到 TopBar 右边的 View
 * @param viewId       该按钮的 id,可在 ids.xml 中找到合适的或新增。手工指定 viewId 是为了适应自动化测试。
 * @param layoutParams
 */
public void addRightView(View view, int viewId, LayoutParams layoutParams) {
    if (mRightLastViewId == DEFAULT_VIEW_ID) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    } else {
        layoutParams.addRule(RelativeLayout.LEFT_OF, mRightLastViewId);
    }
    layoutParams.alignWithParent = true; // alignParentIfMissing
    mRightLastViewId = viewId;
    view.setId(viewId);
    mRightViewList.add(view);
    addView(view, layoutParams);

    // 消除按钮变动对 titleView 造成的影响
    refreshTitleViewLp();
}
 
Example 16
Project: QMUI_Android   File: QMUITopBar.java   Source Code and License Vote up 6 votes
/**
 * 在 TopBar 的右侧添加 View,如果此前已经有 View 通过该方法添加到 TopBar,则新添加进去的 View 会出现在已有View的左侧。
 *
 * @param view         要添加到 TopBar 右边的 View。
 * @param viewId       该按钮的 id,可在 ids.xml 中找到合适的或新增。手工指定 viewId 是为了适应自动化测试。
 * @param layoutParams 生成一个 LayoutParams,当把 Button addView 到 TopBar 时,使用这个 LayouyParams。
 */
public void addRightView(View view, int viewId, LayoutParams layoutParams) {
    if (mRightLastViewId == DEFAULT_VIEW_ID) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    } else {
        layoutParams.addRule(RelativeLayout.LEFT_OF, mRightLastViewId);
    }
    layoutParams.alignWithParent = true; // alignParentIfMissing
    mRightLastViewId = viewId;
    view.setId(viewId);
    mRightViewList.add(view);
    addView(view, layoutParams);
}
 
Example 17
Project: letv   File: TaskGuide.java   Source Code and License Vote up 6 votes
private ViewGroup b(Context context) {
    ViewGroup eVar = new e(this, context);
    g[] gVarArr = this.h.c;
    View iVar;
    ViewGroup.LayoutParams layoutParams;
    if (gVarArr.length == 1) {
        iVar = new i(this, context, gVarArr[0]);
        iVar.setId(1);
        layoutParams = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams.addRule(15);
        eVar.addView(iVar, layoutParams);
    } else {
        iVar = new i(this, context, gVarArr[0]);
        iVar.setId(1);
        View iVar2 = new i(this, context, gVarArr[1]);
        iVar2.setId(2);
        layoutParams = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams.addRule(14);
        layoutParams.setMargins(0, a(6), 0, 0);
        ViewGroup.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams2.addRule(14);
        layoutParams2.setMargins(0, a(4), 0, 0);
        layoutParams2.addRule(3, 1);
        layoutParams2.addRule(5, 1);
        eVar.addView(iVar, layoutParams);
        eVar.addView(iVar2, layoutParams2);
    }
    eVar.setBackgroundDrawable(e());
    return eVar;
}
 
Example 18
Project: letv   File: LivePlayerView.java   Source Code and License Vote up 6 votes
private void initBarrageLayout() {
    this.mBarrageContainId = GenerateViewId.generateViewId();
    LayoutParams params = new LayoutParams(-1, -1);
    View view = LayoutInflater.from(this.mContext).inflate(R.layout.live_barrage_contain, null);
    view.setId(this.mBarrageContainId);
    addView(view, params);
}
 
Example 19
Project: home-automation   File: StoryActivity.java   Source Code and License Vote up 5 votes
/**
 *
 */
private void populateDevices() {
    final LinearLayout mainLinearLayout = findViewById(R.id.mainLinearLayout);
    final CardView addPictureCard = findViewById(R.id.addPictureCard);

    for (final DeviceDAO deviceDAO : story.getDevices()) {
        final View previousDeviceView = mainLinearLayout.findViewById(deviceDAO.getId());
        if (previousDeviceView != null) {
            mainLinearLayout.removeView(previousDeviceView);
        }
        final View deviceView = getLayoutInflater().inflate(R.layout.story_activity_card_device, mainLinearLayout, false);

        // Pass args to buttons in order to perfom some actions on the device
        Button deleteDevice = deviceView.findViewById(R.id.delete_device);
        deleteDevice.setTag(R.id.cardDevice, deviceDAO);

        Button configureDevice = deviceView.findViewById(R.id.configure_device);
        configureDevice.setTag(R.id.cardDevice, deviceDAO);

        deviceView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                showRemoveDeviceDialog(deviceDAO);
                return true;
            }
        });

        // Hide the text if the device has no NetBios name (should be improved by the way)
        TextView name = deviceView.findViewById(R.id.name);
        if (deviceDAO.getName() == null) {
            name.setVisibility(View.GONE);
        } else {
            name.setText(deviceDAO.getName());
        }

        TextView ip = deviceView.findViewById(R.id.ip);
        ip.setText(deviceDAO.getIP());
        TextView vendor = deviceView.findViewById(R.id.vendor);
        vendor.setText(deviceDAO.getVendor());

        // Show the lock icon if device is password protected
        if (deviceDAO.isProtected()) {
            ImageView lockIcon = deviceView.findViewById(R.id.lockIcon);
            lockIcon.setVisibility(View.VISIBLE);
        }

        deviceView.setId(deviceDAO.getId());
        mainLinearLayout.addView(deviceView, mainLinearLayout.indexOfChild(addPictureCard));
    }
}
 
Example 20
Project: XinFramework   File: CommonTitleBar.java   Source Code and License Vote up 5 votes
/**
 * 初始化全局视图
 *
 * @param context
 */
private void initGlobalViews(Context context) {
    ViewGroup.LayoutParams globalParams = new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
    setLayoutParams(globalParams);

    // 构建标题栏填充视图
    boolean supprotStatusBarLightMode = false;
    try {
        supprotStatusBarLightMode = TitleCompatibilityUtil.supportStatusBarLightMode(getContext());
    } catch (ClassCastException e) {
        e.printStackTrace();
    }
    if (fillStatusBar && supprotStatusBarLightMode) {
        int statusBarHeight = TitleCompatibilityUtil.getStatusBarHeight();
        viewStatusBarFill = new View(context);
        viewStatusBarFill.setId(ViewFinder.generateViewId());
        viewStatusBarFill.setBackgroundColor(statusBarColor);
        LayoutParams statusBarParams = new LayoutParams(MATCH_PARENT, statusBarHeight);
        statusBarParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        addView(viewStatusBarFill, statusBarParams);
    }

    // 构建主视图
    rlMain = new RelativeLayout(context);
    rlMain.setId(ViewFinder.generateViewId());
    rlMain.setBackgroundColor(titleBarColor);
    LayoutParams mainParams = new LayoutParams(MATCH_PARENT, titleBarHeight);
    if (fillStatusBar) {
        if (viewStatusBarFill != null)
            mainParams.addRule(RelativeLayout.BELOW, viewStatusBarFill.getId());
    } else {
        mainParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    }

    // 计算主布局高度
    if (showBottomLine) {
        mainParams.height = titleBarHeight - Math.max(1, ScreenUtils.dp2PxInt(0.4f));
    } else {
        mainParams.height = titleBarHeight;
    }
    addView(rlMain, mainParams);

    // 构建分割线视图
    if (showBottomLine) {
        // 已设置显示标题栏分隔线,5.0以下机型,显示分隔线
        viewBottomLine = new View(context);
        viewBottomLine.setBackgroundColor(bottomLineColor);
        LayoutParams bottomLineParams = new LayoutParams(MATCH_PARENT, Math.max(1, ScreenUtils.dp2PxInt(0.4f)));
        bottomLineParams.leftMargin = ScreenUtils.dp2PxInt(15f);
        bottomLineParams.rightMargin = ScreenUtils.dp2PxInt(15f);
        bottomLineParams.addRule(RelativeLayout.BELOW, rlMain.getId());

        addView(viewBottomLine, bottomLineParams);
        mFadeViewList.add(viewBottomLine);
    }
}