我正在尝试在 React Native 中设置我的第一个 Android 应用程序。
现在有这张卡片(react-native-component),里面有多个复选框(见下面的代码)。
每次我尝试只选择一个复选框时,它都会以某种方式检查所有这些复选框。
我知道它与多个状态有关,但我无法让它工作。
我怎样才能只选择一个复选框?
JavaScript 文件:
import React from "react";
import {StyleSheet, ActivityIndicator, ListView, Text, View, Alert, Platform, TouchableOpacity} from 'react-native';
import { Card, CheckBox, Button } from 'react-native-elements';
export default class AgendaItemVote extends React.Component {
constructor(props) {
super(props);
this.state = { checked: false };
}
render(){
return(
<View style={styles.container}>
<Card title="Titel Agendapunt">
<Text style={styles.paragraph}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus at sapien at tellus interdum finibus. Nunc sagittis tincidunt orci, non viverra ligula feugiat id. Phasellus eleifend massa neque, eu scelerisque enim feugiat ac.
</Text>
<View style={{flexDirection: 'row'}}>
<CheckBox
title='Ja'
checked={this.state.checked}
onPress={() => this.setState({
checked: !this.state.checked
})}
/>
<CheckBox
title='Nee'
checked={this.state.checked}
onPress={() => this.setState({
checked: !this.state.checked
})}
/>
<CheckBox
title='Onthouding'
checked={this.state.checked}
onPress={() => this.setState({
checked: !this.state.checked
})}
/>
</View>
<View>
<Button
title="Indienen"
/>
</View>
</Card>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: 40,
backgroundColor: '#ecf0f1',
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
color: '#34495e',
},
});