当前位置:网站首页>Radiogroup dynamically add RadioButton
Radiogroup dynamically add RadioButton
2022-06-11 18:06:00 【xiaoerbuyu1233】
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
for (int i = 0; i < 10; i++) {
RadioButton radioButton = new RadioButton(this);
RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
// Set up RadioButton Margin (int left, int top, int right, int bottom)
lp.setMargins(SizeUtils.dp2px(10), SizeUtils.dp2px(10), SizeUtils.dp2px(10), SizeUtils.dp2px(10));
// Set up RadioButton background
radioButton.setBackgroundResource(R.drawable.radiobutton_background);
radioButton.setTextColor(getResources().getColorStateList(R.drawable.radiobutton_textcolor));
radioButton.setButtonDrawable(null);
// Set the distance around the text
radioButton.setPadding(SizeUtils.dp2px(25), SizeUtils.dp2px(15), SizeUtils.dp2px(25), SizeUtils.dp2px(15));
radioButton.setTextSize(SizeUtils.sp2px(28));
radioButton.setId(i);
radioButton.setChecked(i == 0);
// Set text
radioButton.setText(i + " # pot ");
final int finalI = i;
// Set up radioButton Click events for
radioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(TankWarningSettingActy.this, "this is radioButton " + finalI + " = " + v.getId(), Toast.LENGTH_SHORT).show();
}
});
// take radioButton Add to radioGroup in
radioGroup.addView(radioButton, lp);
}<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scrollbars="none">
<RadioGroup
android:id="@+id/radioGroup"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- <RadioButton-->
<!-- android:id="@+id/tank_warning_setting_1"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="@dimen/dp_10"-->
<!-- android:background="@drawable/radiobutton_background"-->
<!-- android:button="@null"-->
<!-- android:checked="true"-->
<!-- android:padding="@dimen/dp_15"-->
<!-- android:text=" Options 1"-->
<!-- android:textColor="@drawable/radiobutton_textcolor"-->
<!-- android:textSize="@dimen/sp_28" />-->
<!-- <RadioButton-->
<!-- android:id="@+id/tank_warning_setting_2"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="@dimen/dp_10"-->
<!-- android:background="@drawable/radiobutton_background"-->
<!-- android:button="@null"-->
<!-- android:padding="@dimen/dp_15"-->
<!-- android:text=" Options 1"-->
<!-- android:textColor="@drawable/radiobutton_textcolor"-->
<!-- android:textSize="@dimen/sp_28" />-->
</RadioGroup>
</HorizontalScrollView>radiobutton_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/radiobutton_background_unchecked" android:state_checked="false" />
<item android:drawable="@drawable/radiobutton_background_checked" android:state_checked="true" />
</selector>radiobutton_background_unchecked
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- Background fill -->
<solid android:color="@color/white" />
<!-- Round corners -->
<corners android:radius="5dp" />
<stroke
android:width="3dp"
android:color="@color/color_text_gray" /><!-- Stroke , Border width 、 Color -->
</shape>radiobutton_background_checked
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- fill -->
<solid android:color="#f59a23" />
<!-- Round corners -->
<corners android:radius="5dp" />
<!-- <stroke-->
<!-- android:width="3dp"-->
<!-- android:color="@color/color_text_gray" /><!– Stroke , Border width 、 Color –>-->
</shape>radiobutton_textcolor
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_checked="true" />
<item android:color="@color/black" android:state_checked="false" />
</selector> 
Android RadioGroup Dynamic addition RadioButton, Set up margin_guopeng_233 The blog of -CSDN Blog
Use RadioGroup Dynamic addition RadioButton The process of , solve RadioButton Single choice conflict problem - Simple books android in radioGroup Dynamic addition radioButton_Afanbaby The blog of -CSDN Blog
边栏推荐
- Intelligent overall legend, legend of wiring, security, radio conference, television, building, fire protection and electrical diagram [transferred from wechat official account weak current classroom]
- 6-5 count the number of words (file) (*)
- Acwing game 40 [End]
- 密评-----
- How ZABBIX can customize MySQL monitoring items and trigger alarms
- File class learning
- Foreach traverses collections and collection containers
- spawn ./ gradlew EACCES at Process. ChildProcess._ handle. onexit
- ctfhub-sql布尔盲注
- Experiment 3: design and verify all operations represented by linear table sequence on the computer
猜你喜欢

Threejs uses indexeddb cache to load GLB model

Initial egg framework

Upload labs failed to pass the customs halfway and the middle road collapsed

Install MariaDB 10.5.7 (tar package installation)

vulhub

Test and analysis of tidb write hotspot

Kubernetes deploys elk and collects container logs using filebeat

upload-labs通关未半而中道崩殂
![Spring 2021 daily question [week6 not finished]](/img/32/74cff6f057ef9a7941fd6a41dc6635.jpg)
Spring 2021 daily question [week6 not finished]

Test basis: black box test
随机推荐
Global and Chinese markets for ultra high speed printers 2022-2028: Research Report on technology, participants, trends, market size and share
6-3 reading articles (*)
Spring 2021 daily question [end of week4]
Tidb CDC log tables are not eligible to replicate
【C】 ATOI function implementation +offsetof implementation + exchange binary odd and even digits
6-2 writing articles (*)
6-3 batch sum (*)
Tle6389-2g V50's unique pwm/pfm control scheme has a duty cycle of up to 100%, forming a very low differential pressure - keshijin mall
TestPattern error
Bracket generation ---2022/02/25
There are three standards and three methods, i.e. fast growth and quick realization. How to choose the direction for making short videos of we media?
Spring 2021 daily question [week5 not finished]
网络安全威胁情报体系
mariadb spider分片引擎初体验
Mysql8 installation, Navicat installation, sqli labs setup
关于元素位置和尺寸
[practical Script] obtain the line number of a file, and then delete the file content.
Summary of clustering methods
Sqli labs customs clearance hey hey~
6-3 reading articles (*)