Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TextInput onChangeText不工作反应本机_Javascript_Android_React Native - Fatal编程技术网

Javascript TextInput onChangeText不工作反应本机

Javascript TextInput onChangeText不工作反应本机,javascript,android,react-native,Javascript,Android,React Native,我对这个平台很陌生,这是我在这个平台上的第二天。我试图通过创建简单的登录、注册、新闻提要应用程序来自学它。我能够构建登录页面,但当从InputText获取值时,它会显示我的错误信息:“无法同时指定值和子项”,我在这里发布了我的login.js类 export default class LoginScreen extends Component { constructor(props) { super(props); this.state = {

我对这个平台很陌生,这是我在这个平台上的第二天。我试图通过创建简单的登录、注册、新闻提要应用程序来自学它。我能够构建登录页面,但当从InputText获取值时,它会显示我的错误信息:“无法同时指定值和子项”,我在这里发布了我的login.js类

export default class LoginScreen extends Component {

    constructor(props) {
        super(props);
        this.state = {
            username: '',
            password: ''
        };
    }
    login = () => {
        alert(this.state.username + " " + this.state.password);
    }
    render() {
        return (
            <View style={styles.container}>

                <Image source={require('../images/hulk.jpg')} style={styles.backgroundimage}>
                    <View style={styles.content}>
                        <Image source={require('../images/logo.png')} style={styles.logo}>
                        </Image>

                        <View style={styles.inputcontainer}>

                            <TextInput underLineColorAndroid='transparent' style={styles.input} value={this.state.username} onChangeText={(username) => this.setState({ username })} placeholderText='username' > </TextInput>

                            <TextInput secureTextEntry={true} underLineColorAndroid='transparent' style={styles.input} value={this.state.password} onChangeText={(password) => this.setState({ password })} placeholderText='password' placeholderTextColor='black'> </TextInput>

                        </View>
                        <TouchableOpacity onPress={this.login} style={styles.buttonContainer}>
                            <Text style={styles.buttonText}>LOGIN</Text>
                        </TouchableOpacity>
                    </View>
                </Image>
            </View>
        );
    }
}
导出默认类LoginScreen扩展组件{
建造师(道具){
超级(道具);
此.state={
用户名:“”,
密码:“”
};
}
登录=()=>{
警报(this.state.username+“”+this.state.password);
}
render(){
返回(
this.setState({username}}占位符text='username'>
this.setState({password}}占位符text='password'占位符text='black'>
登录
);
}
}
请让我知道我的代码哪里出错了


问候

你能试试这个吗

export default class LoginScreen extends Component {

constructor(props) {
    super(props);
    this.state = {username: '',password: ''};
}
login = () => {
    alert(this.state.username + " " + this.state.password);
}
render() {
    return (
        <View style={styles.container}>
            <Image source={require('../images/hulk.jpg')} style={styles.backgroundimage}>
                <View style={styles.content}>
                    <Image source={require('../images/logo.png')} style={styles.logo}>
                    </Image>
                    <View style={styles.inputcontainer}>
                        <TextInput 
                        underLineColorAndroid='transparent' 
                        style={styles.input} 
                        value={this.state.username} 
                        onChangeText={(text) => this.setState({ username: text })} 
                        placeholderText='username'/>

                        <TextInput 
                        secureTextEntry={true} 
                        underLineColorAndroid='transparent' 
                        style={styles.input} 
                        value={this.state.password} 
                        onChangeText={(text) => this.setState({ password:text })} 
                        placeholderText='password' 
                        placeholderTextColor='black'/>
                    </View>
                    <TouchableOpacity onPress={this.login()} style={styles.buttonContainer}>
                        <Text style={styles.buttonText}>LOGIN</Text>
                    </TouchableOpacity>
                </View>
            </Image>
        </View>
    );
}
导出默认类LoginScreen扩展组件{
建造师(道具){
超级(道具);
this.state={用户名:'',密码:'};
}
登录=()=>{
警报(this.state.username+“”+this.state.password);
}
render(){
返回(
this.setState({username:text})
占位符text='username'/>
this.setState({password:text})}
占位符text='password'
占位符textcolor='black'/>
登录
);
}

你能在那里更新你的代码吗?请应用正确的格式,这样我就可以阅读并帮助你了。@NisargThakkar,请检查一点帮助,先生,每次我在输入框内写东西时都会显示警报,但TouchableOpacity上的onpress事件不启动登录功能可能,我知道背后的原因。对不起,我不明白你可以请你给我一些更多的细节。我只想调用登录功能,按登录按钮,这是在TouchableOpacity标签,现在登录功能被调用时,每次我写的东西在用户名输入字段或密码输入字段。请让我知道是什么让onChangeText起作用,我想理解。谢谢你,先生!!!onChangeText是在文本输入的文本更改时调用的回调函数。请将代码替换为
{this.login()}style={style.buttonContainer}>login