Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
select single radio button in react native flatlist

I am React Native Beginner and am using expo-radio-button.

But i am unable to select a single radio button at a time in flatlist.

if i select single button it will select only one button.

help me to fix this. i need to show and select yes or no in the radio button for each questions

Click here to see output that i want

var myArray = [
  {
    isSignReq: "1",
    sno: "1",
    yesno: "0",
  },
  {
    isSignReq: "1",
    sno: "2",
    yesno: "0",
  },
  {
    isSignReq: "1",
    sno: "3",
    yesno: "0",
  },
];

const [account, setAccount] = useState([]);

const setFormSubmit = (val) => {
  console.log(val);
};

<FlatList
  data={myArray}
  keyExtractor={() => {
    return (
      new Date().getTime().toString() +
      Math.floor(Math.random() * Math.floor(new Date().getTime())).toString()
    );
  }}
  renderItem={(itemData) => {
    return (
      <View style={{ flexDirection: "row", marginVertical: "2%" }}>
        <Text style={styles.data1}>{itemData.item.sno}</Text>
        <Text style={styles.data2}>{itemData.item.name}</Text>
        <View style={{ width: "30%", marginLeft: "1%" }}>
          <RadioButtonGroup
            onSelected={(value) => {
              setFormSubmit(value), setAccount(value);
            }}
            selected={account}
            size={22}
            containerStyle={{ flexDirection: "row" }}
          >
            <RadioButtonItem label={"Yes"} value={itemData.item.isSignReq} />
            <RadioButtonItem label={"No"} value={itemData.item.yesno} />
          </RadioButtonGroup>
        </View>
      </View>
    );
  }}
/>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

renderItem = ({item, index}) => {
 .....
<RadioButton
  innerColor={Colors.darkBlue}
  outerColor={Colors.lightGray}
  animation={'bounceIn'}enter code here
  isSelected={this.state.selectedIndex === index}
  onPress={() => {this.onPress(index)}}
/>
}

and replace onPress with

onPress = (index) => {
   this.setState({ selectedIndex: index });
 }

and update FlatList with extraData props as FlatList needs to be re-rendered as

<FlatList
   keyExtractor={this._keyExtractor}
   data={this.state.data}
   renderItem={this.renderItem}
   ItemSeparatorComponent={this.renderSeparator}
   extraData={this.state}
 />

demo: https://snack.expo.dev/HkzA9cCSB

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda