Add an onclick event to a button
Get Button Object
Button Aiyo = (Button) Findviewbyid (r.id.button1); Aiyo.setonclicklistener (new Onclicklistener () { @Override public void OnClick (View v) {///tv.settext ("Woceshi"); //pop-up Tips toast.maketext (getapplicationcontext (), ' Hello ', Toast.length_short). Show (); } );
Open a new window (activity)
// Create a Form object New Intent (); Newwindow.setclass (mainactivity. this, NewWindow. class ); // The first is the current form class, and the second is a new form class (form name. Class) startactivity (NewWindow); // start a new form
The current form passes values to the new form
This is what the current form does
New Intent (); Newwindow.setclass (mainactivity. this, NewWindow. class ); // New Open Window pass value New bundle (); Bundle.putstring ("Bundlekey", "Zongwenlong"); Newwindow.putextras (bundle) ; // New open Window Pass value end
The code on the three lines above is actually a bit more complex, and can be written as follows
New Window Pass value 1
Newwindow.putextra ("Key", "value");
New Window value 1 endstartactivity (NewWindow);
What the new form does
Write in the oncreate of the new form
// get the value from the previous form This . Getintent (). Getextras (); LOG.E ("Zllmsg", Bundle.getstring ("Bundlekey")); // gets the value that came from the previous form end
The new window closes and then passes the value back to the old window
What the old window did
New Intent (); Newwindow.setclass (mainactivity. this, NewWindow. class ); // New Open Window pass value New bundle (); Bundle.putstring ("Bundlekey", "Zongwenlong"); Newwindow.putextras (bundle) ; // New open Window Pass value End // startactivity (NewWindow); Startactivityforresult (NewWindow, 1111);//This 1111 is a unique code, also need to use
new window to do things, write a button event
Newnew Bundle (); Bundle.putstring ("Zllfanhui", "Zonglonglongfanhui"); Intent.putextras (bundle); Setresult (1111, intent); finish ();
Old window to do things again, to implement an interface
@Override protected void onactivityresult (intint resultcode, Intent data) { // TODO auto-generated method Stub Super. Onactivityresult (Requestcode, ResultCode, data); LOG.E ("Zllmsg", Data.getextras () getString ("Zllfanhui"));
Android Development Basics Small Notes, add button events, open new form, form pass value, callback