Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda