gpt4 book ai didi

android - React Native 中如何聚焦下一个字段输入?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:57:28 24 4
gpt4 key购买 nike

我需要在 android 平台的 react native 中关注下一个字段输入。但是focus()函数,在android react native中是不存在的,只在IOS中存在。

这是怎么做到的?我使用 React Native 和 typescript 。

enter image description here

最佳答案

焦点功能工作得很好。

<View style={{flexDirection: 'row'}}>
<Text style={{flex: 1}}>Enter Name: </Text>
<TextInput ref="name" onChangeText={(name) => this.setState({name})} style={{flex: 1}}
onSubmitEditing={() => this.refs.age.focus()}/>
</View>
<View style={{flexDirection: 'row'}}>
<Text style={{flex: 1}}>Enter Age: </Text>
<TextInput ref="age" keyboardType="numeric" onChangeText={(age) => this.setState({age})} style={{flex: 1}}
onSubmitEditing={() => this.refs.sport.focus()}/>
</View>
<View style={{flexDirection: 'row'}}>
<Text style={{flex: 1}}>Enter Favourite Sport: </Text>
<TextInput ref="sport" onChangeText={(sport) => this.setState({sport})} style={{flex: 1}}/>
</View>

希望这对您有所帮助。这是针对安卓的。

关于android - React Native 中如何聚焦下一个字段输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43495030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com