How to load a new window in Android How to close a window and pass a value to another window

Source: Internet
Author: User

I'm here there are two Windows the second window will pass the first window to the value displayed on the second window of the button is destroyed this window the first window button is loaded in the second window and passed the value to the second window (there are several button ID and TextView ID I will not mention should understand)

This is mostly used by intent to find out how much this object uses.

This is the Java code for the first window mainactivity

Package Com.example.vmpdump.windw;import Android.content.intent;import android.support.v7.app.AppCompatActivity; Import Android.os.bundle;import Android.view.view;import Android.widget.button;public class MainActivity extends appcompatactivity {@Override protected void onCreate (Bundle savedinstancestate) {super.oncreate (Savedinstan        Cestate);        Setcontentview (R.layout.activity_main);        Button Bt=findviewbyid (R.id.button);    Bt.setonclicklistener (Onclicklistener); } private View.onclicklistener Onclicklistener =new View.onclicklistener () {@Override public void oncli            CK (view view) {Intent Intent =new Intent (); Intent.setclass (Mainactivity.this,main2activity.class);//The first is the current window context second is to load the window class Intent.putextra ("key", "haha haha" );//pass parameter key value pair to another window equivalent to map can pass array, object what serializable this is the startactivity of the object (intent);//Start intent//If you is the window generated directly with the IDE manifest without adding <activity android:name= ". Main2activity android:label= "Window caption" ></activity> he automatically added};} 

This is the second window of Java class code main2activity

Package Com.example.vmpdump.windw;import Android.content.intent;import android.support.v7.app.AppCompatActivity; Import Android.os.bundle;import android.view.view;import android.widget.button;import Android.widget.TextView; public class Main2activity extends Appcompatactivity {    @Override    protected void OnCreate (Bundle Savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main2);        Intent Intent =getintent ();        Bundle Bundle=intent.getextras ();        String temp=  bundle.getstring ("key");        TextView textview= Findviewbyid (r.id.lab);        Button Button=findviewbyid (r.id.button2);        Button.setonclicklistener (Onclicklistener);        Textview.settext (temp);    }    Private View.onclicklistener onclicklistener=new View.onclicklistener () {        @Override public        void OnClick ( View view) {finish ();//Destroy this window to automatically return to the loading window}    };

  

How to load a new window in Android How to close a window and pass a value to another window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.