简体   繁体   English

android studio 2.3上的输入和输出

[英]input and output on android studio 2.3

This is kind of beginner/noob question, but I want to use InputActivity.java and activity_input.xml as the one that the user use to input data. 这是一种初学者/菜鸟问题,但是我想使用InputActivity.java和activity_input.xml作为用户用来输入数据的问题。 The code for the input are as shown below: 输入的代码如下所示:

InputActivity.java InputActivity.java

package com.lukmanyahoo.denny.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class InputActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input);
    }

    //Send data to HasilActivity.java

}

activity_input.xml activity_input.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lukmanyahoo.denny.myapplication.InputActivity">

    <EditText
        android:id="@+id/editText"
        android:layout_width="569dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="636dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:hint="@string/umur"
        android:inputType="number"
        app:layout_constraintBottom_toTopOf="@+id/editText"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="DuplicateIds,NotSibling,RtlHardcoded"
        app:layout_constraintVertical_bias="0.251" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="569dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:hint="@string/daerah"
        android:inputType="textPersonName"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editText"
        tools:ignore="MissingConstraints,RtlHardcoded" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:text="@string/jurusan"
        android:textSize="30sp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:ignore="MissingConstraints"
        android:layout_marginTop="32dp"
        app:layout_constraintTop_toBottomOf="@+id/editText2"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp" />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="569dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        tools:ignore="RtlHardcoded">

        <RadioButton
            android:id="@+id/radioButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/informatika" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="569dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/sistem_informasi"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="178dp" />

    </RadioGroup>

    <Button
        android:id="@+id/button3"
        android:layout_width="569dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:text="@string/kirim"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup"
        tools:ignore="RtlHardcoded" />

</android.support.constraint.ConstraintLayout>

The code for the output part of my application are shown below: 我的应用程序输出部分的代码如下所示:

HasilActivity.java HasilActivity.java

package com.lukmanyahoo.denny.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class HasilActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hasil);
    }
}

activity_hasil.xml activity_hasil.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lukmanyahoo.denny.myapplication.HasilActivity">

    <TableLayout
        android:layout_width="568dp"
        android:layout_height="791dp"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/umur"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="  "
                tools:layout_editor_absoluteX="58dp"
                tools:layout_editor_absoluteY="169dp" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/daerah"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="  " />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/jurusan"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="  " />
        </TableRow>

    </TableLayout>

</android.support.constraint.ConstraintLayout>

Thanks for taking time answering this. 感谢您抽出宝贵的时间回答此问题。 I am new in giving question here. 我是在这里提出问题的新手。

In your InputActivity 在您的InputActivity中

public class InputActivity extends AppCompatActivity { 公共类InputActivity扩展了AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_input);
}

//Send data to HasilActivity.java
Intent intent = new Intent(this, HasilActivity.class);
// put your data here
 intent.putExtra("value_one", editText.getText().toString().trim());
 intent.putExtra("value_two", editText2.getText().toString().trim());
 startActivity(intent)

}

and in your HasilActivity 在你的HasilActivity中

public class HasilActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hasil);

    String value = getIntent().getStringExtra("value_one");
    String value2 = getIntent().getStringExtra("value_two");
}
}

that is :) 那是 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM