本文整理汇总了Java中android.view.View.setId方法的典型用法代码示例。如果您正苦于以下问题:Java View.setId方法的具体用法?Java View.setId怎么用?Java View.setId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.setId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onChildViewAdded
import android.view.View; //导入方法依赖的package包/类
/**
* {@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);
}
}
示例2: onBindView
import android.view.View; //导入方法依赖的package包/类
@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());
}
示例3: addFixedView
import android.view.View; //导入方法依赖的package包/类
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);
}
示例4: getView
import android.view.View; //导入方法依赖的package包/类
@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;
}
示例5: addFixedToolItemView
import android.view.View; //导入方法依赖的package包/类
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);
}
示例6: addView
import android.view.View; //导入方法依赖的package包/类
@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);
}
}
}
示例7: addPanelLayout
import android.view.View; //导入方法依赖的package包/类
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();
}
示例8: addViewToCellLayout
import android.view.View; //导入方法依赖的package包/类
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;
}
示例9: onBindView
import android.view.View; //导入方法依赖的package包/类
@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());
}
示例10: getView
import android.view.View; //导入方法依赖的package包/类
@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;
}
示例11: setId
import android.view.View; //导入方法依赖的package包/类
/**
* 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());
}
}
}
示例12: getTargetView
import android.view.View; //导入方法依赖的package包/类
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();
}
示例13: createStatusBarView
import android.view.View; //导入方法依赖的package包/类
/**
* 生成一个和状态栏大小相同的半透明矩形条
*
* @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;
}
示例14: addItem
import android.view.View; //导入方法依赖的package包/类
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;
}
示例15: addRightView
import android.view.View; //导入方法依赖的package包/类
/**
* 在 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();
}