Android Learning Code3 Layout on
Last Update:2015-08-06
Source: Internet
Author: User
<span id="Label3"></p><p><p>Andriod system is a system based on event-driven behavior<br>Andirod four ways to add event drivers</p></p><p><p>The first customization of an inner class implementation Onclicklistener<br>Private class Mylistenner implements onclicklistener{<br>public void OnClick (View W) {<br><br>}</p></p><p><p>}<br>Then the OnCreate method</p></p><p><p>Call button dail= (button) this.findbyviewid (r.id.et_numer);<br>Dail.setonclicklistnener (new Mylistenner ());</p></p><p><p>The second way is by directly invoking anonymous anonymous inner classes using the</p></p><p><p><br>The third kind of mainactivy directly implements the Onclicklistener interface<br>Implement the OnClick () method</p></p><p><p><br>Fourth custom function, then use the business logic</p></p><p><p>Real column 1 phone dial real column<br>Package com.org.login;</p></p><p><p>Import com.org.msg.MessageTools;</p></p><p>Import android.app.Activity;<br>Import android.content.Intent;<br>Import android.net.Uri;<br>Import android.os.Bundle;<br>Import android.text.TextUtils;<br>Import android.util.Log;<br>Import android.view.Menu;<br>Import android.view.MenuItem;<br>Import android.view.View;<br>Import android.view.View.OnClickListener;<br>Import android.widget.Button;<br>Import android.widget.EditText;<br>Import android.widget.Toast;<br>/**<br>* The main meeting of the Activty<br>* @author WANGSL<br>*<br>*/<br>public class Mainactivity extends Activity implements onclicklistener{<br>Private String tag= "mainactivity";<br>Private EditText ets_number; Enter phone number<br>@Override<br>protected void OnCreate (Bundle Savedinstancestate) {<br>Super.oncreate (savedinstancestate);<br>Setcontentview (r.layout.tel_phone_main);<br>Button bt_telphone= (button) Findviewbyid (r.id.bt_telphone); If the button type, the button type is required to receive<br><br>A variety of ways to listen for events, the first custom inner class<br>Bt_telphone.setonclicklistener (new Mylistenner ());<br><br>The second way to call anonymous internal classes is to use<br>Bt_telphone.setonclicklistener (new Onclicklistener () {<br>//<br>@Override<br>public void OnClick (View V) {<br>TODO auto-generated Method Stub<br>//<br>// }<br>// });<br><br>The third class itself implements the OnClick interface Mainactivity extends Activity implements Onclicklistener<br>ets_number= (EditText) Findviewbyid (r.id.ets_number);<br>Bt_telphone.setonclicklistener (this);<br><br>Fourth customizing a method call<br><br>}<br><br><br><br>/**<br>* Custom content class<br>* @author WANGSL<br>*<br>*/<br>Private class Mylistenner implements onclicklistener{</p><p><p>@Override<br>public void OnClick (View V) {<br>TODO auto-generated Method Stub<br>Callphone ();<br><br><br>}</p></p><p><br>}<br><br>public void Sendphone () {<br><br>Callphone ();<br>}<br><br><br>/*<br>* Make a phone call<br>*/<br>public void Callphone () {<br>String number=ets_number.gettext (). toString ();<br>System.out.print ("number===" +number);<br>LOG.E (tag, "number===" +number);<br>If (textutils.isempty (number)) {//textutil character comparison tool classes need to be used frequently<br>Toast.maketext (mainactivity.this, messagetools.tel_phome_error_mes, toast.length_short). show (); Toast is a Message object<br>return;<br>}<br><br>Phone calls to related objects<br>Intent intent=new Intent ();<br>Intent.setaction (intent. action_call); Perform a phone call operation<br>Intent.setdata (uri.parse ("tel:" +number)); Perform input dialing phone number<br>StartActivity (intent); Start dialing<br>}<br><br><br><br>@Override<br>public void OnClick (View V) {<br>TODO auto-generated Method Stub<br>Callphone ();<br>}<br><br><br>}</p><p><p> Layout tel_phone_main.xml <br> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= " Match_parent "<br> android:layout_height=" match_parent "<br> android: paddingbottom= "@dimen/activity_vertical_margin" <br> android:paddingleft= "@dimen/activity_ Horizontal_margin "<br> android:paddingright=" @dimen/activity_horizontal_margin "<br> android:paddingtop= "@dimen/activity_vertical_margin" <br> tools:context= " Com.org.login.MainActivity "; </p></p><p><p> <textview <br> android:id= "@+id/tv_input_ Number "<br> android:layout_width=" wrap_content "<br> android:layout_height= "wrap_content" <br> android:layout_alignparentstart= "true" <br> android:text= "@string/ Please_input_number "/> </p></p><p><p> <edittext <br> android:id= "@+id/ets_number" <br> android:lines= "1" <br> Android:layout_width= "match_parent" <br> android:layout_height= "wrap_ Content "<br> android:layout_alignparentstart=" true "<br> android:layout_below= "@+id/tv_input_number" <br> android:inputtype= "phone" <br> android:labelfor= "@+id/et_ <br> </edittext> </p></p><p><p><button<br>Android:id= "@+id/bt_telphone"<br>Android:layout_width= "wrap_content"<br>android:layout_height= "wrap_content"<br>Android:layout_alignparentstart= "true"<br>android:layout_below= "@+id/ets_number"<br>android:layout_margintop= "16dp"<br>android:text= "@string/tel_phone_btn"/></p></p><p><p><br></RelativeLayout></p></p><p><p></p></p><p><p>Android Learning Code3 Layout on</p></p></span>