Android 流式布局 RadioGroup
2018-07-20 来源:open-open
1.使用方法
package com.example.radiogroup; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.view.ViewGroup.LayoutParams; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; public class MainActivity extends Activity { private SelfRadioGroup mRadioLayout; private List<String> mSelectDataList; private RadioButton radioButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRadioLayout = (SelfRadioGroup) findViewById(R.id.items_parent_Single); initList(); //根据内容的数量添加RadioButton for (int i = 0; i < mSelectDataList.size(); i++) { radioButton = new RadioButton(this); radioButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); radioButton.setTextColor(Color.BLACK); radioButton.setText(mSelectDataList.get(i)); mRadioLayout.addView(radioButton); } mRadioLayout.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int id = group.getCheckedRadioButtonId(); RadioButton by = (RadioButton) findViewById(id); System.out.println("选择的内容:"+by.getText()); } }); } /** * 获取RadioButton内容 */ private void initList() { mSelectDataList = new ArrayList<String>(); mSelectDataList.add("批发了贷款"); mSelectDataList.add("部件"); mSelectDataList.add("文明行政村"); mSelectDataList.add("单位综合检查"); mSelectDataList.add("单位"); mSelectDataList.add("事件"); mSelectDataList.add("门前三包"); mSelectDataList.add("批发了贷款"); mSelectDataList.add("批发"); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:Go语言冒泡排序实现代码
最新资讯
热门推荐