EditText 입력값 다른 Activity 에서 출력하기
다른곳도 수정해야 하지만 파란색도 빠트리지 말고 수정해줍니다.
Code for MainActivity.java file.
package com.passedittextvalue_android_examples.com; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { EditText SendValue; Button SendEditTextValue; Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SendEditTextValue = (Button)findViewById(R.id.button1); SendValue = (EditText)findViewById(R.id.editText1); SendEditTextValue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { intent = new Intent(getApplicationContext(),SecondActivity.class); intent.putExtra("EdiTtEXTvALUE", SendValue.getText().toString()); startActivity(intent); } }); } }
Code for activity_main.xml layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.passedittextvalue_android_examples.com.MainActivity" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" > </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_marginTop="26dp" android:text="Click Here to Pass edittext value to another activity in android" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="Main Activity" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>
Code for SecondActivity.java file.
package com.passedittextvalue_android_examples.com; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class SecondActivity extends Activity { TextView receive; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); receive = (TextView)findViewById(R.id.textView1); receive.setText(getIntent().getStringExtra("EdiTtEXTvALUE")); } }
Code for activity_second.xml layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.passedittextvalue_android_examples.com.SecondActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="22dp" android:text="Second Activity" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>
Screenshot:
Click Here to download Pass EditText value to another activity in android project.
[출처] https://www.android-examples.com/pass-edittext-value-to-another-activity-in-android/
'프로그래밍 > Android (Java)' 카테고리의 다른 글
Layout 에 관한 모든것 (0) | 2018.04.10 |
---|---|
EditText 입력 후 Button 누르면 Toast 로 출력시키는 예제 (0) | 2018.04.10 |
Android 개발환경 구성 (ver 2018-03-21) (0) | 2018.03.21 |
안드로이드 음성 인식 기능 (STT) (0) | 2017.10.10 |
웹서버를 통한 파일 자동 업데이트 (0) | 2017.09.27 |