简体   繁体   中英

How to render buttons in a flatlist react-native?

I have two buttons which i'm trying to render in a flatlist so that it iterates and displays multiple times as a list. How should i do it?

<FlatList
  data={this.state.data}
  extraData={this.state}
  renderItem={this.renderItem}
  keyExtractor={items => items.id}
/>
<TouchableOpacity onPress={this.onPressButtonPlay.bind(this)}>
  <Text style={styles.buttonText}> </Text>
</TouchableOpacity>

<TouchableOpacity onPress={this.onPressButtonPause.bind(this)}>
  <Text style={styles.buttonText}>{this.state.pause ? 'Resume' : 'Pause'}</Text>
</TouchableOpacity>

Just simply insert it within your renderItem function:

renderItem = ({item}) => {
  return(
      <TouchableWithoutFeedback>
        <TouchableOpacity>
            {this.renderButton()}
        </TouchableOpacity>
      <TouchableWithoutFeedback>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM