当前位置: 首页>>代码示例>>Java>>正文


Java RadioButton.setId方法代码示例

本文整理汇总了Java中android.widget.RadioButton.setId方法的典型用法代码示例。如果您正苦于以下问题:Java RadioButton.setId方法的具体用法?Java RadioButton.setId怎么用?Java RadioButton.setId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.RadioButton的用法示例。


在下文中一共展示了RadioButton.setId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildNavViews

import android.widget.RadioButton; //导入方法依赖的package包/类
private void buildNavViews() {
    if (mAdapter == null)
        return;

    clearNavItems();
    isCursorWidthInited = false;

    for (int i = 0; i < mAdapter.getCount(); i++) {
        RadioButton item = mAdapter.getNavigatorButton(i, navButtonGroup);

        item.setId(i);
        item.setChecked(i == 0);

        navButtonGroup.addView(item, i);
    }

    navCursor = mAdapter.getCursor(navContainer);

    if (navCursor != null) {
        navContainer.addView(navCursor, 0);
    }
}
 
开发者ID:KaneJinCN,项目名称:android-CategoryPager,代码行数:23,代码来源:CategoryPagerNav.java

示例2: setCheckedId

import android.widget.RadioButton; //导入方法依赖的package包/类
/** 查找复合控件并设置id */
private void setCheckedId(ViewGroup vg) {
    int len = vg.getChildCount();
    for (int i = 0; i < len; i++) {
        if (vg.getChildAt(i) instanceof RadioButton) {// 如果找到了,就设置check状态
            final RadioButton button = (RadioButton) vg.getChildAt(i);
            int id = button.getId();
            // generates an id if it's missing
            if (id == View.NO_ID) {
                id = button.hashCode();
                button.setId(id);
            }
            button.setOnCheckedChangeListener(mChildOnCheckedChangeListener);
        } else if (vg.getChildAt(i) instanceof ViewGroup) {// 迭代查找并设置
            ViewGroup childVg = (ViewGroup) vg.getChildAt(i);
            setCheckedId(childVg);
        }
    }
}
 
开发者ID:ZouJianFeng-Marco,项目名称:Navigation-bar,代码行数:20,代码来源:FlowRadioGroup.java

示例3: onChildViewAdded

import android.widget.RadioButton; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void onChildViewAdded(View parent, View child) {
    if (parent == MultiRadioGroup.this ) {
        List<RadioButton> btns = getAllRadioButton(child);
        if(btns != null && btns.size() > 0){
            for(RadioButton btn : btns){
                int id = btn.getId();
                // generates an id if it's missing
                if (id == View.NO_ID && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    id = View.generateViewId();
                    btn.setId(id);
                }
                btn.setOnCheckedChangeListener(
                        mChildOnCheckedChangeListener);
            }
        }
    }
    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:24,代码来源:MultiRadioGroup.java

示例4: setSingleSelectItems

import android.widget.RadioButton; //导入方法依赖的package包/类
public void setSingleSelectItems(String[] singleSelectItems, int selectedItem, final OnClickListener onClickListener) {
    if (singleSelectItems != null && singleSelectItems.length > 0) {
        selectableItemsContainer.removeAllViews();
        selectableItemsContainer.setVisibility(View.VISIBLE);
        RadioGroup radioGroup = (RadioGroup) getLayoutInflater().inflate(R.layout.cfdialog_single_select_item_layout, selectableItemsContainer)
                                                                .findViewById(R.id.cfstage_single_select_radio_group);
        radioGroup.removeAllViews();
        for (int i = 0; i < singleSelectItems.length; i++) {
            String item = singleSelectItems[i];
            RadioButton radioButton = (RadioButton) getLayoutInflater().inflate(R.layout.cfdialog_single_select_radio_button_layout, null);
            radioButton.setText(item);
            radioButton.setId(i);
            final int position = i;
            if (position == selectedItem) {
                radioButton.setChecked(true);
            }
            radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked && onClickListener != null) {
                        onClickListener.onClick(CFAlertDialog.this, position);
                    }
                }
            });
            radioGroup.addView(radioButton);
        }
    } else {
        selectableItemsContainer.setVisibility(View.GONE);
    }
}
 
开发者ID:Codigami,项目名称:CFAlertDialog,代码行数:31,代码来源:CFAlertDialog.java

示例5: initCheckGroup

import android.widget.RadioButton; //导入方法依赖的package包/类
private void initCheckGroup(final OrderTestModel.OrderItemCheckListBean model, LayoutInflater inflater) {
        for (int z = 0; z < model.checkItemSuggestions.size(); z++) {
            final OrderTestModel.OrderItemCheckListBean.CheckItemSuggestionsBean item = model.checkItemSuggestions.get(z);
//            final RadioButton ckview = (RadioButton)inflater.inflate(R.layout.fragment_test_item_ck, null);
            final RadioButton ckview = new RadioButton(activity);
            ckview.setText(item.suggestionOption);
            if (item.isChecked.equals("1")) {
                checkId = item.checkItemSuggestionsId;
                ckview.setChecked(true);
            } else {
                ckview.setChecked(false);
            }
            ckview.setTag(item.checkItemSuggestionsId);
            ckview.setTextColor(this.getResources().getColor(R.color.gray_text));
            ckview.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
            ckview.setTextSize(18);
            ckview.setId(z);
            ckview.setPadding(2, 0, 12, 0);
            ckview.setGravity(Gravity.CENTER | left);
            Drawable drawable = getResources().getDrawable(
                    R.drawable.checkbox_selector_circle_bac);
            // 这一步必须要做,否则不会显示.
            drawable.setBounds(0, 0, drawable.getMinimumWidth(),
                    drawable.getMinimumHeight());
            ckview.setCompoundDrawables(drawable, null, null, null);
            ckview.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    checkId = (String) ckview.getTag();
                }
            });
            llsugestcontain.addView(ckview);
        }
    }
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:35,代码来源:TestItemView.java

示例6: getRadios

import android.widget.RadioButton; //导入方法依赖的package包/类
private static View getRadios(Activity activity, LayoutInflater inflater, final SignUpEventOptions options) {
    View view = inflater.inflate(R.layout.event_sign_up_radios, null);
    ((TextView) view.findViewById(R.id.tv_label)).setText(options.getLabel() + (options.isRequired() ? "" : "(选填)") + ":");
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.rg_options);
    RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMarginEnd(100);
    if (!TextUtils.isEmpty(options.getOption())) {
        String[] list = options.getOption().split(";");
        String[] status = null;
        if (!TextUtils.isEmpty(options.getOptionStatus()))
            status = options.getOptionStatus().split(";");
        for (int i = 0; i < list.length; i++) {
            RadioButton button = new RadioButton(activity);
            button.setLayoutParams(params);
            button.setText(list[i]);
            if (!TextUtils.isEmpty(options.getDefaultValue())) {
                button.setChecked(list[0].equals(options.getDefaultValue()));
                options.setValue(options.getDefaultValue());
            } else {
                button.setChecked(i == 0);
                options.setValue(list[0]);
            }
            boolean enable;
            if (status == null)
                enable = true;
            else if (status.length <= i)
                enable = true;
            else
                enable = "0".equals(status[0]);
            button.setId(i);
            button.setEnabled(enable);
            radioGroup.addView(button);
        }
    }
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            String s[] = options.getOption().split(";");
            if (s != null)
                options.setValue(s[checkedId]);
        }
    });
    return view;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:47,代码来源:ViewFactory.java

示例7: initView

import android.widget.RadioButton; //导入方法依赖的package包/类
private void initView() {
    String[] btnNameArr = groupBtnName.split("#");
    String[] btnCodeArr = groupBtnCode.split("#");

    Log.d("gyw", btnNameArr.length + "   length  :" + btnCodeArr.length);

    if ((btnNameArr.length < 2) || (btnCodeArr.length < 2)) {
        throw new RuntimeException("names和codes的格式不正确...");
    }

    for (int i = 0; i < btnCodeArr.length; i++) {

        //使用布局文件写方便
        RadioButton rb = (RadioButton) View.inflate(mContext, R.layout.view_item_group_radio_button, null);

        if (btnCodeArr.length == 2) {
            if (i == 0) {
                rb.setBackgroundResource(R.drawable.left_button_selector);
                rb.setChecked(true);
            } else if (i == 1) {
                rb.setBackgroundResource(R.drawable.right_button_selector);
            }
        } else {
            if (i == 0) {
                rb.setBackgroundResource(R.drawable.left_button_selector);
                rb.setChecked(true);
            } else if (i == btnCodeArr.length - 1) {
                rb.setBackgroundResource(R.drawable.right_button_selector);
            } else {

                rb.setBackgroundResource(R.drawable.mid_button_selector);
            }
        }

        rb.setId(i);
        rb.setTag(btnCodeArr[i]);
        rb.setText(btnNameArr[i]);

        mRg.addView(rb);
    }
}
 
开发者ID:InnoFang,项目名称:FamilyBond,代码行数:42,代码来源:GroupButtonView.java


注:本文中的android.widget.RadioButton.setId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。