标签: radio-button

如何根据给定的计数动态添加单选按钮?

我试过这个代码..当模拟器启动时,它会在一行中显示三个单选按钮.但我需要一个按钮事件.即; 如果我点击按钮,它应该询问单选按钮的数量.那么如果我给出计数,它必须根据给定的计数显示单选按钮.例如,如果我将计数设为3,则必须在一行中显示三个单选按钮.非常感谢您的帮助.提前致谢.

  public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        for(int row=0; row < 1; row++)
        {
            LinearLayout ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.HORIZONTAL);
            for(int i = 1; i < 4; i++) {
                RadioButton rdbtn = new RadioButton(this);
                rdbtn.setId((row * 2) + i);
                rdbtn.setText("Radio " + rdbtn.getId());
                ll.addView(rdbtn);
            }
            ((ViewGroup)findViewById(R.id.radiogroup)).addView(ll);
        }
    }
    }
Run Code Online (Sandbox Code Playgroud)

这是xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".MainActivity" >

    <RadioGroup …
Run Code Online (Sandbox Code Playgroud)

android dynamic count button radio-button

28
推荐指数
3
解决办法
7万
查看次数

Android RadioButton textColor选择器

我有一个选择textColorRadioButton是这样的:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="#fff"/>
    <item android:state_focused="true" android:color="#f00"/>
    <item android:state_pressed="true" android:color="#0f0"/>
    <item android:state_focused="false" android:state_pressed="false" android:color="#00f"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

我预计所选择的那个RadioButton将具有与其他颜色不同的颜色.

但是,所有RadioButtons都有蓝色文本(使用android:state_focused ="false"android:state_pressed ="false"),甚至是所选的.

我究竟做错了什么?

android radio-button

28
推荐指数
3
解决办法
3万
查看次数

Android:如何更改RadioButton的大小

RadioButton我的应用程序中有很多s.RadioButtons对我来说太大了.有没有办法让它们变小?

size android radio-button

27
推荐指数
4
解决办法
5万
查看次数

在Android中的RadioGroup中获取RadioButton数组

有没有办法RadioButton在Android 中获取s 的数组(或集合)RadioGroup?我想将单个侦听器添加到单选按钮,但我没有看到任何明显的迭代方法.

arrays iteration android radio-group radio-button

27
推荐指数
1
解决办法
2万
查看次数

在SingleChoice模式下使用RadioButton的Android ListView和自定义行布局

我有一个ListView,它处于singleChoice模式.我想要的只是在侧面显示一个RadioButton,当点击高亮显示它被选中时,当点击另一个时,一个返回到未选择状态,新的一个被选中.为什么这么难?这不应该是这么复杂.我已经花了DAYS寻找合适的答案而且我什么也没找到,所以我希望以清晰简洁的方式提出要求.

我对listview的布局(R.layout.view_orders):

<?xml version="1.0" encoding="utf-8"?>
<ListView 
        android:choiceMode="singleChoice"
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@drawable/list_divider"
        android:dividerHeight="1px"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:cacheColorHint="#00000000">
</ListView>
Run Code Online (Sandbox Code Playgroud)

我的自定义行(R.layout.orders_row):

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:app="http://schemas.android.com/apk/res/com.xxx.xxxxxx"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="6dip">

    <com.xxx.xxxxxx.VerticalLabelView
        app:text="SHORT"
        app:textColor="#666"
        app:textSize="14sp"
        android:id="@+id/state"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true" />

    <TextView
        android:id="@+id/quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/state" 
        android:layout_centerVertical="true"
        android:gravity="center"
        android:textSize="40sp"
        android:layout_margin="2dip"
        android:minWidth="30dip"
        android:textColor="#555" />


    <RelativeLayout
        android:layout_toRightOf="@id/quantity"
        android:layout_centerVertical="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/instrument"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:textColor="#333"
            android:layout_marginLeft="2dip"
            android:layout_marginRight="2dip"
            />


        <TextView
            android:id="@+id/deets"
            android:layout_below="@id/instrument"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:textColor="#888" …
Run Code Online (Sandbox Code Playgroud)

android listview listviewitem radio-button

26
推荐指数
2
解决办法
5万
查看次数

android RadioButton按钮可绘制重力

我正在动态生成RadioButtons

RadioButton radioButton=new RadioButton(context);  

LayoutParams layoutParams=new LayoutParams(radioWidth,radioHeight);
layoutParams.gravity=Gravity.CENTER;

radioButton.setLayoutParams(layoutParams);
radioButton.setGravity(Gravity.CENTER);

BitmapDrawable bitmap = ((BitmapDrawable)drawableResource);
bitmap.setGravity(Gravity.CENTER);

radioButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.itabs_radio));
radioButton.setButtonDrawable(bitmap);
Run Code Online (Sandbox Code Playgroud)

你可以看到我拼命想把按钮的重力设置为中心,但没有理由它总是居中和左对齐,继承人的原因 - 安卓单选按钮的默认样式:

<style name="Widget.CompoundButton">
<item name="android:focusable">true</item> 
<item name="android:clickable">true</item>
<item name="android:textAppearance">?android:attr/textAppearance</item> 
<item name="android:textColor">?android:attr/textColorPrimaryDisableOnly</item> 
<item name="android:gravity">center_vertical|left</item> 
</style>

<style name="Widget.CompoundButton.RadioButton">
<item name="android:background">@android:drawable/btn_radio_label_background</item> 
<item name="android:button">@android:drawable/btn_radio</item> 
</style>
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将按钮对齐到中心吗?

android center radio-button drawable

26
推荐指数
2
解决办法
2万
查看次数

以编程方式创建RadioButtons

我想创建一系列单选按钮,这些按钮对应于Android应用程序中的字符串数组.单选按钮应切换要从数组中显示的内容.我该怎么做呢?

android radio-button

26
推荐指数
1
解决办法
4万
查看次数

这是一个IE11单选按钮渲染错误(它们看起来像googly眼睛)?

我正在一个有几个单选按钮的网站上工作.在大多数浏览器中,一切看起来都很好,但在IE11中,一些单选按钮看起来像googly眼睛.现在,这是IE11中的一个错误还是我做错了什么?

编辑:真实网站的屏幕截图:

在此输入图像描述

这是一个例子(在IE11中尝试看看效果):http://jsfiddle.net/TjZA5/

这是我浏览器的缩放屏幕截图(Windows 7上的IE11): 在此输入图像描述

您可以清楚地看到中心圆盘和外圆之间的不同间距.HTML是相同且有效的(许多<input type="radio" checked="checked">元素),CSS也是如此(只是稍微限制一点,使效果更明显).我想知道它是否是IE渲染代码中的舍入错误?

更新:我将此问题作为反馈项提交给Microsoft Connect(http://connect.microsoft.com/IE/feedback/details/814911/radio-buttons-look-like-googly-eyes-in-ie11)并获得了回应称这是一种视错觉.我认为不是,所以我提供了更多的例子.我现在更确信它是IE中的一个错误,但我不得不拭目以待.

更新Windows 10中的Edge浏览器:

我注意到微软最新的浏览器Edge(Windows 10附带)中存在此问题:

边缘的Googly眼睛

Microsoft Connect问题还没有更新,所以我想我们现在仍然坚持使用googly eyed单选按钮.

更新:Microsoft Connect问题已关闭为"无法修复"

我在developer.microsoft.com上创建了一个新问题:https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7114234/,希望有一天他们能解决这个问题.

更新:微软已经更新了问题,说它已经修复了!

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8516392/

我还没有机会在Windows 10的新版本上测试这个,但是会尽快做到.

html css radio-button internet-explorer-11 microsoft-edge

26
推荐指数
1
解决办法
5590
查看次数

如何在Xcode 7 OSX中创建NSRadioButton组

我正在按照本教程学习如何创建单选按钮组.但似乎Radio Group在Xcode 7库中不再可用,我没有找到太多关于它的信息.我如何创建这样的东西:

在此输入图像描述

非常感谢.

cocoa radio-button swift xcode7

26
推荐指数
3
解决办法
1万
查看次数

带有react-hook-form的单选按钮

我用react-hook-form创建了一个表单。它在控制台中正确记录“fullName”和“city”,但不记录单选按钮。使用单选按钮,您会得到结果“null”。

我的代码如下。

import React from 'react'
import './App.css';
import {useForm} from "react-hook-form";

function App() {
    const {register, handleSubmit} = useForm();

    function onSubmitButton(data) {
        console.log(data)
    }

    return (
        <>
            <h1>Order weather</h1>
            <form onSubmit={handleSubmit(onSubmitButton)}>
                <input
                    {...register("fullName")}
                    type="text"
                    name="fullName"
                    placeholder="Name and surname"
                    id="name"
                />
                <input
                    {...register("city")}
                    type="text"
                    name="city"
                    placeholder="City"
                    id="city"
                />
                <p>I would like to:</p>
                <label htmlFor="field-rain">
                    <input
                        {...register("rain")}
                        type="radio"
                        name="weather"
                        value="rain"
                        id="field-rain"
                    />
                    Rain
                </label>
                <label htmlFor="field-wind">
                    <input
                        {...register("wind")}
                        type="radio"
                        name="weather"
                        value="wind"
                        id="field-wind"
                    />
                    Lots of wind
                </label>
                <label htmlFor="field-sun">
                    <input
                        {...register("sun")} …
Run Code Online (Sandbox Code Playgroud)

forms radio-button reactjs react-hook-form

26
推荐指数
1
解决办法
8万
查看次数