要想獲取文本框的值,首先我們需要看一下官方文檔的解釋:

這里的意思是說當文本框的內容改變的時候,文本框的輸入的內容就會作為一個參數進行傳遞。因此我們就可以獲取到文本框里面的內容就好了。
1 constructor (props) { 2 super (props) 3 this.state = { 4 screen: this.initScreen(), 5 txtValue: null, 6 dataSource: new ListView.DataSource({ 7 rowHasChanged: (row1, row2) => row1 !== row2 8 }), 9 loaded: false 10 } 11 } 12 13 。。。。 14 15 16 <TextInput 17 selectTextOnFocus = {true} 18 onChangeText={(text) => { 19 this.state.txtValue = text 20 this.getContent() 21 }} 22 23 。。。 24 25 getContent () { 26 ToastAndroid.show(this.state.txtValue, ToastAndroid.LONG) 27 }
