日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Activity跳转

發(fā)布時(shí)間:2023/11/30 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Activity跳转 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本例中MainActivity為:FirstActivity.java

FirstActivity如下:

package com.wyl.intentmultiactivitytest;import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText;public class FirstActivity extends Activity {//Button btn01;Button btn02;EditText et;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.firstctivity);// 綁定頁面btn01 = (Button) findViewById(R.id.button1);btn02 = (Button) findViewById(R.id.button2);et = (EditText)findViewById(R.id.editText1);btn01.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub// 1.上下文對(duì)象,Context// 2.目標(biāo)文件Intent intent = new Intent(FirstActivity.this,SecondActivity.class);System.out.println("======kaishi :====");startActivity(intent);// 實(shí)現(xiàn)跳轉(zhuǎn)到第二個(gè)頁面}});btn02.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub// 1.上下文對(duì)象,Context// 2.目標(biāo)文件Intent intent = new Intent(FirstActivity.this,SecondActivity.class);System.out.println("======第一個(gè)頁面的第二種跳轉(zhuǎn)kaishi :====");startActivityForResult(intent, 1);;// 實(shí)現(xiàn)跳轉(zhuǎn)到第二個(gè)頁面}});}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);if(requestCode==1&&resultCode==2){String plnr1 = data.getStringExtra("plnr");String plnr2 = data.getExtras().getString("plnr");System.out.println("==========:"+plnr1+",plnr2:"+plnr2);et.setText("data.getStringExtra('plnr1')"+plnr1+",plnr2 = data.getExtras().getString('plnr')的方式"+plnr2);}} }

  SecondActivity:

package com.wyl.intentmultiactivitytest;import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;public class SecondActivity extends Activity {Button btn01;Button btn02;EditText et;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.second_activity);// 綁定頁面System.out.println("=====wo shi the second yemian =====");btn01 = (Button) findViewById(R.id.button21);btn02 = (Button) findViewById(R.id.button22);et = (EditText)findViewById(R.id.editText01);btn01.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(SecondActivity.this, FirstActivity.class);System.out.println("==cong dier tiaodao diyiye==");startActivity(intent);}});btn02.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent();String content = et.getText().toString();//獲取評(píng)論的內(nèi)容intent.putExtra("plnr", content);//2是狀態(tài)碼,隨便自己設(shè)置,用來判斷是哪個(gè)頁面的返回值,自己不弄混了就行setResult(2, intent); //這是最關(guān)鍵的一步,Toast.makeText(SecondActivity.this, intent.getExtras().getString("plnr"),1000);finish();//關(guān)閉該頁面,就會(huì)自動(dòng)返回到了第一頁了。}});} }

  相關(guān)的layout文件:

firstctivity.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><Buttonandroid:id="@+id/button1"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="new Intent(context,目標(biāo)activity.class),startActivity(intent)方式跳轉(zhuǎn)" /><Buttonandroid:id="@+id/button2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="第二種方式跳轉(zhuǎn)" /><EditTextandroid:id="@+id/editText1"android:layout_width="match_parent"android:layout_height="wrap_content"android:ems="10" android:hint="我只是個(gè)提示框框而已"><requestFocus /></EditText></LinearLayout>

  second_activity.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><EditTextandroid:id="@+id/editText01"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="錄入要返回到第一頁的內(nèi)容" /><Buttonandroid:id="@+id/button21"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="我是第二個(gè)activity頁面" /><Buttonandroid:id="@+id/button22"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="startActivityForResult方式返回,并且回傳數(shù)據(jù)" /> </LinearLayout>

  效果圖如下:

?

轉(zhuǎn)載于:https://www.cnblogs.com/Sunnor/p/4731564.html

總結(jié)

以上是生活随笔為你收集整理的Activity跳转的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。