How to Send ListView Item Click Value to Another Activity in React Native

React Navigation library gives us a simple method to transfer the values between multiple activities on Activity open time. So in this tutorial we would going to create an react native application which could Send ListView Item Click Value to Another Activity. When app user click on any ListView item first it would retrieve that item and then transfer selected item to next activity.

Note : You need to install the React Navigation library in your project because without this library you cannot add Activities in Both Android and iOS applications.

Contents in this project Send ListView Item Click Value to Another Activity tutorial :

1. Start a fresh React Native project. If you don’t know how then read my this tutorial.

2. Read our Previous tutorial to Open New Activity on Button Click in React Native.

3. Download and Install the react-navigation library in your project using using NPM server. So open your project’s folder in Command Prompt / Terminal and Type below command to install react-navigation library and make sure that you run the Command Prompt in Administrator mode.

Screenshot of CMD after done installing :


4. Open your project’s index.android.js / index.ios.js file and Import AppRegistry, StyleSheet, Text, View and ListView component in your project.

5. Import StackNavigator module from react-navigation library in your project.

6. Make a new Class named as FirstActivity and extends component to it. This should be our First Activity Class Screen.

7. Create constructor in MainActivity class with super method. Now define ListView data source using State. This should be our all ListView items.

8. Create ListViewItemSeparatorLine function . This function would create a line between each ListView item.

9. Create OpenSecondActivity function and pass the rowData inside it. Here rowData would be send by ListView when user clicks on any ListView item. Now navigate to second activity and using the ListViewClickItemHolder variable we would send the selected rowData value to second activity. Here ListViewClickItemHolder is the identifier to send and receive the transfer value.

10. create static navigationOptions to set the Main Activity title.

11. Finally create a Parent View in render’s return block and into the parent view creating the ListView component.

Screenshot of FirstActivity :

12. Create another class named as SecondActivity .

Here this.props.navigation.state.params.ListViewClickItemHolder is used to receive the sent value from FirstActivity.

Screenshot of SecondActivity :

Send ListView Item Click Value13. Create StackNavigator method to navigate activities . This step is very important.

14. Create style sheet classes .

15. Complete source code for App.js File :

Screenshots in Android mobile phone application :

Send ListView Item Click Value

Screenshot in iOS mobile phone application :