1. index.android.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  ScrollView,
  TextInput,
  View ,
} from 'react-native';

var styles = require('./Style/customStyle');

import Button from 'react-native-button';
import RadioButton from 'react-native-radio-button'

class AwesomeProject extends Component {

  constructor(props){
    super(props)

    this.state = {
      username: '',
      password: '',
    }
  }

  render() {
    return (
    <ScrollView style={styles.content}>
      <View style={styles.content}>

        <Text style={styles.welcome}>
          Create Account
        </Text>

        <Text style={styles.textStyle}>
          Name
        </Text>

        <TextInput
          style={styles.textInputStyle}
          placeholder="Enter Name"
          returnKeyLabel = {"next"}
          onChangeText={(text) => this.setState({text})}
        />

        <Button style={styles.buttonStyle}>
              Submit
        </Button>

        </View>
      </ScrollView>
    );
  }
}

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

推荐答案

首先,你必须将你的数据储存在一个州.

例子:

<TextInput
          style={styles.textInputStyle}
          placeholder="Enter Name"
          returnKeyLabel = {"next"}
          onChangeText={(text) => this.setState({text})}
/>

然后,您必须传递一个函数,当您单击按钮时,该函数将执行如下操作:

<Button
        onPress={() => function }>

恢复你的价值:this.state.key

例子:

class AwesomeProject extends Component {

  constructor(props){
    super(props)

    this.state = {
      username: '',
      password: '',
    }
  }

  _handlePress() {
     console.log(this.state.username);
     console.log(this.state.password);
  }

  render() {
    return (
    <ScrollView style={styles.content}>
      <View style={styles.content}>

        <Text style={styles.welcome}>
          Create Account
        </Text>

        <Text style={styles.textStyle}>
          Name
        </Text>

        <TextInput
          style={styles.textInputStyle}
          placeholder="Enter Name"
          returnKeyLabel = {"next"}
          onChangeText={(text) => this.setState({username:text})}
        />

        <Text style={styles.textStyle}>
          Name
        </Text>

        <TextInput
          style={styles.textInputStyle}
          placeholder="Enter Name"
          returnKeyLabel = {"next"}
          onChangeText={(text) => this.setState({password:text})}
        />

        <Button 
          onPress={() => this._handlePress()}
          style={styles.buttonStyle}>
              Submit
        </Button>

        </View>
      </ScrollView>
    );
  }
}

我没有测试这段代码,但它应该可以工作

React-native相关问答推荐

如何停止在Expo路由中将新文件显示为菜单列表?

如何在API调用期间将本地存储(Expressc存储)中的令牌传递到后台

react 本机函数不通过usContext触发

将值从一个 js 文件传递​​到 react native 中的另一个 js 文件:react native

将屏幕标题更新为所选标签导航的标题

React Native Child Parent 通信

如何使用 AsyncStorage React Native 缓存 API 数据

React - 类内的useContext

如何使用 InteractionManager.runAfterInteractions 使导航器过渡更快

在使用 redux-persist 重新水化存储之前加载初始状态的默认值

Typescript:onPress 类型

react-native createbottomtabnavigator 隐藏标签栏标签

你如何从 React Native 的 EventEmitter 实例中移除一个监听器?

React Native + Jest EMFILE:too many open files error

react-native async 函数返回 promise 但不返回我的 json 数据?

try 在 Android 上运行我的 React Native 应用程序时出错

React Native TextInput blur TouchableHighlight 按下事件

等待模块失效的超时

DeviceInfo 原生模块未正确安装

React Native - 为什么执行这个函数?