<span id="Label3"></p><p><p>The processing model for event snooping consists of three members: event sources, events, and event Listeners.<br></p></p><p><p>The Listener-based event processing model typically consists of several steps:</p></p>1, access to common interface components;<br>2. Implement event Listener Class<br>3. Register the Listener object with the normal component<br><p><p>When a specified event occurs on the event source, Android triggers the corresponding event listener, and the event listener invokes the appropriate method to handle the Event.</p></p><p><p></p></p><pre name="code" class="java">public class Remotecontrolactivity extends Activity {EditText ipet; EditText socketet; Button button; @Override public void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); Ipet = (EditText) Findviewbyid (r.id.ipedittext); Socketet = (EditText) Findviewbyid (r.id.socketedittext); Gets the button component named Connectbutton in the program button = (button) Findviewbyid (r.id.connectbutton); Binds the event listener to the button and implements the Listener Class's method button.setonclicklistener (new onclicklistener () {@Override public voi D onClick (View v) {String ipnum = ipet.gettext (). toString (); int socketnum = Integer.parseint (socketet.gettext (). toString ()); Settings.ipnum =ipnum; Settings.scoketnum = socketnum; Try {datagramsocket socket = new Datagramsocket (); InetAddress serveraddress = Inetaddress.getbyname (ipnum); Intent Intent = new Intent (Remotecontrolactivity.this,controlactivity.class); RemoteControlActivity.this.startActivity (intent); RemoteControlActivity.this.finish (); Toast.maketext (remotecontrolactivity.this, "connection succeeded", toast.length_short). show (); } catch (Exception E) {//TODO auto-generated catch block E.printstacktrace (); } } }); }}</pre><br>As you can see from the above code, the event source being monitored is a button named Connectbutton (that is, the event source), and the Setonclicklistener method is called to register the event listener object Onclicklistener () to the event Source. The event listener class Onclicklistener () and its method OnClick (View V) are Implemented.<p><p></p></p><p><p>This uses the anonymous inner class as the event listener class<br></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android Event Listener Processing</p></p></span>
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