Select a row in ListView react-native to get detail

我怕爱的太早我们不能终老 提交于 2019-12-05 13:06:55

In your renderRow method (in your case renderMovie), simply pass the movie in onPress prop of TouchableOpacity, something like this:

renderMovie(movie) {
    title1 = movie.title;
    year1 = movie.year;

    return (
    <TouchableOpacity onPress={() => _handlePressList(movie)}>    // SEE HERE!!
      <View style={styles.container}>
        <Image
          source={{uri: movie.posters.thumbnail}}
          style={styles.thumbnail}
        />
        <View style={styles.rightContainer}>
          <Text style={styles.title}>{movie.title}</Text>
          <Text style={styles.year}>{movie.year}</Text>
        </View>
      </View>
    </TouchableOpacity>
    );
  },

_handlePressList(movie){
    this.props.navigator.push({id: 2, movie.title1, movie.year1});
  },

Then you can do whatever you want with the movie.

Hope it's helpful.

renderMovie(movie) {
title1 = movie.title;
year1 = movie.year;

return (
<TouchableOpacity onPress={this._handlePressList.bind(this, movie)}
  <View style={styles.container}>
    <Image
      source={{uri: movie.posters.thumbnail}}
      style={styles.thumbnail}
    />
    <View style={styles.rightContainer}>
      <Text style={styles.title}>{movie.title}</Text>
      <Text style={styles.year}>{movie.year}</Text>
    </View>
  </View>
</TouchableOpacity>
);
 },

_handlePressList(movie){
this.props.navigator.push({id: 2, movie.title1, movie.year1});
},

This will solve the problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!