The previous section we looked at the system parameters of the main interface, we should still have the impression that the following
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/2A/03/wKiom1OBaMPA44eCAAGD_nD11Yo835.jpg "title=" 1.png " alt= "Wkiom1obampa44ecaagd_nd11yo835.jpg"/>
Let's take a look at the changes and deletions in this section.
In the previous section I have introduced the system parameter modification and the deletion of the WebService, as follows
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/2A/03/wKiom1OBaXXz5yCpAAF6ejO-Dpk830.jpg "title=" Qq20140525115010.png "alt=" Wkiom1obaxxz5ycpaaf6ejo-dpk830.jpg "/>
Where the system parameter modification is described as follows
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/2A/03/wKioL1OBadfDd_XDAAKDLuZEILU162.jpg "title=" Qq20140525115234.png "alt=" Wkiol1obadfdd_xdaakdluzeilu162.jpg "/>
System parameter deletion is defined as follows
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/2A/03/wKiom1OBajejQY0qAAJYmEpKktY887.jpg "title=" Qq20140525115324.png "alt=" Wkiom1obajejqy0qaajymepkkty887.jpg "/>
The next thing we need to know is how to implement the function of modifying and deleting buttons. Remember the last section we used the system-provided simpleadapter to show the ListView data. This is not possible to implement the response of the button. So before implementing the functions of these two buttons, you first need to enable them to respond to click events. So we need to define our own adapter.
Public class customadapter extends baseadapter {private list<map<string, Object>> dataList;private LayoutInflater mInflater;private Context context;private string[] keystring;private int[] valueviewid; Holder holder;public customadapter (context context,list<map<string, object>> datalist, int resource,string[] from, int[] to) {this.dataList = dataList;this.context = context;mInflater = (Layoutinflater) This.context.getSystemService (context.layout_inflater_service); keystring = new string[ from.length];valueviewid = new int[to.length]; System.arraycopy (from, 0, keystring, 0, from.length); System.arraycopy (to, 0, valueviewid, 0, to.length);} @Overridepublic int getcount () {return datalist.size ();} @Overridepublic &nbsP;object getitem (int position) {return datalist.get (position);} @Overridepublic long getitemid (int position) {return position;} Public void removeitem (int position) {datalist.remove (position); This.notifydatasetchanged ( );} Public view getview (int position, view convertview, viewgroup parent) {if (convertview != null) {holder = (holder) convertview.gettag ();} else {convertview = minflater.inflate (R.layout.systemcodedetailtemplate, null); Holder = new holder ();holder.labcname = (TextView) convertview.findviewbyid ( Valueviewid[0]);holder.labdata = (TextView) convertview.findviewbyid (valueviewid[1]); holder.labdisplay = (TextView) convertview.findviewbyid (valueviewid[2]); holder.btnupdate = (Button) convertview.findviewbyid (valueviewid[3]);holder.btndelete = (Button) convertview.findviewbyid (valueviewid[4]); Convertview.settag (holder);} Map<string, object> appinfo = datalist.get (position);if (appInfo != NULL) {string cname = appinfo.get (Keystring[0]). toString (); String data = appinfo.get (Keystring[1]). toString (); String displaycontent = appinfo.get (Keystring[2]). toString (); Holder.labCname.setText (CNAME); Holder.labData.setText (data); Holder.labDisplay.setText (displaycontent); Holder.btnDelete.setOnClickListener (new viewbuttonlistener (position)); Holder.btnUpdate.setOnClickListener (New viewbuttonlistener (position)) ;} Return convertview;}
In the constructor we pass in the data source, get the instantiated object that loads the XML layout file Minflater, and pass in the data source map<string, the key value in object>, the ID of the element in the page, Used to match the value taken with the key.
And then overwrite some of the Baseadapter's methods. Here the main look at this getview.
First determine if the root layout template has been loaded, if it is loaded, get holder, otherwise instantiate holder, and assign the elements within the template to holder. This holder how to understand, I think is XML layout template on the elements of the carrier. Any element on the template can be obtained by holder. The next appinfo is the data map<string of the row selected by the ListView on the current interface, OBJECT>, so here we can get value by the key value. Will the value be assigned to each corresponding element in the holder vector in the future?
String cname = Appinfo.get (keystring[0]). toString (); String data = Appinfo.get (Keystring[1]). toString (); String displaycontent = Appinfo.get (Keystring[2]). toString (); Holder.labCname.setText (CNAME); Holder.labData.setText (data); Holder.labDisplay.setText (displaycontent);
OK, this is actually rewriting the display of the ListView implementation. Let's take a look at the focus.
Holder.btnDelete.setOnClickListener (new Viewbuttonlistener (position)); Holder.btnUpdate.setOnClickListener (new Viewbuttonlistener (position));
These two buttons are the rightmost two action buttons in our first picture. We separately registered for its Click event listener, its listener implementation class is Viewbuttonlistener, let's look at
Class viewbuttonlistener implements onclicklistener {private int position;object cname;Object data;Object displayContent; edittext txtename; edittext txtcname; edittext txtdata; edittext txtdisplaycontent; edittext txtremark; view layout; Viewbuttonlistener (int position) {this.position = position;cname = datalist.get ( Position). Get ("CNAME");d ata = datalist.get (position). Get ("Data");d isplaycontent = Datalist.get (position). Get ("displaycontent"); Layoutinflater inflater = getlayoutinflater (); Layout = inflater.inflate ( R.layout.systemcodemodify, (ViewGroup) findviewbyid (R.id.modifydialog));txtename = (EditText) layout.findviewbyid (R.id.txtename);txtcname = (EditText) layout.findviewbyid ( R.id.txtcname);txtdata = (EditText) layout.findviewbyid (r.id.txtdata); txtdisplaycontent = (EditText) layOut.findviewbyid (R.id.txtdisplay);txtremark = (EditText) layout.findviewbyid (R.id.txtRemark);} @Overridepublic void onclick (View view) {int vid = view.getid ();if ( Vid == holder.btnupdate.getid ()) {txtename.settext (owner.ename); Txtcname.settext (cname.toString ()); Txtdata.settext (data.tostring ()); Txtdisplaycontent.settext (displaycontent.tostring ()); TxtEname.setEnabled ( FALSE); txtcname.setenabled (false); txtdata.setenabled (false); final alertdialog.builder builder = new alertdialog.builder (owner); Builder.seticon (R.drawable.info); Builder.settitle ( R.string.titlesystemcodemodifyname); Builder.setview (layout); Builder.setpositivebutton (r.string.btnsave, NULL); Builder.setnegativebutton (R.string.btnclose,null);final alertdialog dialog = Builder.create ();d ialog.show ();d Ialog.getbutton (alertdialog.button_positive). Setonclicklistener (new View.onclicklistener () {@Overridepublic void onclick (view v) {if (Txtdisplaycontent.gettext (). toString (). Trim (). Length () == 0) {showmessage ("Display value cannot be empty!"); return;} Soapobject soapobject = new systemcodedetail (). Modifysystemcode (Ename, data.tostring (), txtdisplaycontent.gettext (). ToString (). Trim (). ToString (), txtremark.gettext (). toString ()); Boolean issuccess = boolean.valueof (Soapobject.getproperty ("issuccess"). ToString ());if ( issuccess) {showmessage (r.string.savesuccess);d Ialog.dismiss ();} else {string errormsg = soapobject.getproperty ("ErrorMessage"). ToString (); ShowMessage (errormsg);}});} else if (Vid == holder.btndelete.getid ()) {soapobject soapobject = new systemcodedetail (). Deletesystemcode (Ename, data.tostring ()); Boolean issuccess = boolean.valueof (Soapobject.getproperty ("issuccess"). ToString ());if ( issuccess) {showmessaGE (r.string.deletesuccess);} else {string errormsg = soapobject.getproperty ("ErrorMessage"). ToString (); ShowMessage (errormsg);}}} class holder {public textview labcname;public textview labdisplay;public Textview labdata;public button btnupdate;public button btndelete;}}
OK, we see, in the constructor, we get the elements, because our save and delete button's listener that implementation class is Viewbuttonlistener. So in the OnClick event, we need to know which button triggered the event. So get the ID first, if the ID is btnupdate. Then go to modify the logic, otherwise go to delete logic.
First take a look at the change logic, create a dialog, this dialog load is an activity, popup interface is what, in the constructor has such a paragraph
Layout = Inflater.inflate (r.layout.systemcodemodify, (ViewGroup) Findviewbyid (R.id.modifydialog));
We also saw this when we created dialog.
Builder.setview (layout);
So the interface that pops up is r.layout.systemcodemodfy. Let's take a look at this interface
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/2A/03/wKiom1OBd3fzEHsUAAG0t3nTa_A427.jpg "title=" Qq20140525124956.png "alt=" Wkiom1obd3fzehsuaag0t3nta_a427.jpg "/>
<?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:id=" @+id/modifydialog " android:orientation=" vertical "><tablelayout android:id=" @+id/tabmain "android:layout_width=" fill_parent " android:layout_height=" wrap_content "android:padding=" 3dip " android:stretchcolumns=" 1 "><tablerow><textview android:text=" @string/labename " Android:textsize= "6pt" android:gravity= "right" /><edittext android:id= "@+id/txtename" Android:maxlength= "android:singleline=" ></EditText></TableRow><TableRow>< "true" textview android:text= "@string/labcname" android:textsize= "6pt" android:gravity= "right" /> <edittext android:id= "@+id/txtcname" android:maxlength= "android:singleline=" "true" ></ Edittext></tablerow><tablerow> <textview android:text= "@string/labdata" android:textsize= "6pt" android:gravity= "right" / ><edittext android:id= "@+id/txtdata" android:singleline= "true" ></edittext></ tablerow><tablerow><textview android:text= "@string/labdisplay" android:textsize= "6pt" Android:gravity= "Right" /><edittext android:id= "@+id/txtdisplay" android:singleline= "true "></edittext></tablerow><tablerow><textview android:text=" @string/labremark " Android:textsize= "6pt" android:gravity= "right" /><edittext android:id= "@+id/txtRemark" android:maxlines= "4" ></EditText></TableRow></TableLayout><!--<linearlayout android:orientation= "Horizontal"--><!--android:gravity= "Center_horizontal" android:layout_ Width= "Fill_parent"--><!--android:layout_height= "wrap_content" >--><!--<button android: Id= "@+id/btnsave" android:layout_width= "110DP"--><!--android:layout_height= "45DP" android:layout_gravity= "Center_horizontal"- <!--android:text= "@string/btnsave" android:textstyle= "bold"--><!--android:textcolor= "@color/blue "></Button>--><!--<button android:id=" @+id/btnclose " android:layout_width=" 110DP "- -><!--android:layout_gravity= "center_horizontal" android:layout_height= "45DP"--><!--android: text= "@string/btnclose" android:textstyle= "bold"--><!--android:textcolor= "@color/blue" ></ button>--><!--</LinearLayout>--></LinearLayout>
OK, that's the interface, table layout.
Look down again, this is the SetIcon (set pop-up page icon), Settitle (popup title), Setpostivebutton and Setnegativebutton. We all know that the pop-up page will always automatically close when the button is clicked, in order to solve this problem, our button click event has been rewritten
Dialog.getbutton (alertdialog.button_positive). Setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View v) {}}
In the Click event, if the validation failed, the interface does not close, otherwise it is closed. Let's look at the effect and the interface doesn't turn off.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/2A/03/wKiom1OBd7HBJO34AAGvVi3ssLM968.jpg "title=" Qq20140525125049.png "alt=" Wkiom1obd7hbjo34aagvvi3sslm968.jpg "/>
If the save is successful, close the interface
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/2A/04/wKiom1OBeTbSnolJAAEhqOdm-Cs199.jpg "title=" Qq20140525125708.png "alt=" Wkiom1obetbsnoljaaehqodm-cs199.jpg "/>
OK, let's take a look at the modified call
Private soapobject modifysystemcode (String ename, string data,string display, string remark) {soapobject request = new soapobject (NAMESPACE, METHOD _name_put); Systemcodeentity codeentity = new systemcodeentity (); Codeentity.setproperty (0, ename) ; Codeentity.setproperty (2, data); Codeentity.setproperty (3, display); Codeentity.setproperty (4, Remark); Propertyinfo pi = new propertyinfo ();p i.setname ("systemcodeentity");p I.setvalue (codeEntity );p I.settype (Codeentity.getclass ()); Request.addproperty (PI); Soapserializationenvelope soapenvelope = new soapserializationenvelope (SOAPENVELOPE.VER11) ; Soapenvelope.dotnet = true;soapenvelope.setoutputsoapobject (request); Httptransportse httpts = new httptransportse (URL);soapenvelope.bodyout = httpts; Soapenvelope.setoutputsoapobject (Request);// set request Parameters Soapenvelope.addmapPing (namespace, "systemcodeentity", codeentity.getclass ()); Try {httpts.call (SOAP_ACTION_PUT, soapenvelope);} catch (ioexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} catch (xmlpullparserexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} soapobject result = null;try {result = (Soapobject) Soapenvelope.getresponse ();} catch (soapfault e) {// TODO Auto-generated catch Blocke.printstacktrace ();} Return result;}
The
is not much to say here. Look again at the deleted code
Private soapobject deletesystemcode (String ename, string data) {SoapObject Request = new soapobject (Namespace, method_name_delete); Propertyinfo pi = new propertyinfo ();p i.setname ("ename");p I.settype (String.class); Pi.setvalue (ename), Request.addproperty (PI);p i = new propertyinfo ();p i.setname ("data"); Pi.settype (String.class);p i.setvalue (data); Soapserializationenvelope soapenvelope = new soapserializationenvelope (SOAPENVELOPE.VER11) ; Soapenvelope.dotnet = true;soapenvelope.setoutputsoapobject (request); Httptransportse httpts = new httptransportse (URL);soapenvelope.bodyout = httpts; Soapenvelope.setoutputsoapobject (Request);// set request parameter Try {httpts.call (soap_action_delete, SoapEnvelope);} catch (ioexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} catch (Xmlpullparserexception e) {// todo auto-generated catch blocke.printstacktrace ();} soapobject result = null;try {result = (Soapobject) Soapenvelope.getresponse ();} catch (soapfault e) {// TODO Auto-generated catch Blocke.printstacktrace ();} Return result;}
OK, this article ends here.
This article is from the "Technology Creation value" blog, please be sure to keep this source http://leelei.blog.51cto.com/856755/1416819