About Android accessing database through WebService issues

Source: Internet
Author: User
Tags soap


==================== Problem Description ====================
Access to the database, the phone can delete the database data is not to show the data in the database do not know where the problem, with the HTTP
This is the way I see all the information in my WebService:
Public list<string> selectallcargoinfor ()         {             list<string> list =  new List<string> ();             try            {                 string sql =  "select *  from c ";                 sqlcommand cmd = new sqlcommand (Sql,sqlcon);                 sqldatareader reader = cmd. ExecuteReader ();                 while  (reader. Read ())                 {                     // Add the result set information to the return vector                      list. ADD (Reader[0]. ToString ());                     list. ADD (Reader[1]. ToString ());                     list. ADD (Reader[2]. ToString ());                 }                 reader. Close ();                 cmd. Dispose ();            }             catch (Exception)              {            }             return list;         }

Next comes the android:
This is the method of setting the ListView in Mainactivity
private void Setlistview () {listview.setvisibility (view.visible); list

This is the Operation class:
Public list

Connection WebService that method Httpconnsoap should be no problem because the database of additions and deletions are possible, is unable to achieve this display all the information to the ListView This function do not know why, Logcat is also a green no problem

Information in Logcat:
05-02 15:51:40.642:i/system.out (3678): <?xml version= "1.0" encoding= "Utf-8"? ><soap:envelope xmlns:soap= " http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:xsd=" http ://www.w3.org/2001/XMLSchema "><soap:body><selectallcargoinforresponse xmlns=" http://tempuri.org/" ><selectallcargoinforresult><string>1</string><string>rice</string><string >100</string><string>2</string><string>dog</string><string>50</ String><string>3</string><string> Idiot </string><string>25</string></ Selectallcargoinforresult></selectallcargoinforresponse></soap:body></soap:envelope>
05-02 15:51:40.647:i/system.out (3678): <?xml version= "1.0" encoding= "Utf-8"?
05-02 15:51:40.647:i/system.out (3678): Soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"
05-02 15:51:40.647:i/system.out (3678): Soap:body
05-02 15:51:40.647:i/system.out (3678): Selectallcargoinforresponse xmlns= "http://tempuri.org/"
05-02 15:51:40.647:i/system.out (3678): Selectallcargoinforresult
05-02 15:51:40.647:i/system.out (3678): 0
05-02 15:51:40.647:i/system.out (3678): string>1</string
05-02 15:51:40.647:i/system.out (3678): string>rice</string
05-02 15:51:40.647:i/system.out (3678): string>100</string
05-02 15:51:40.647:i/system.out (3678): string>2</string
05-02 15:51:40.652:i/system.out (3678): string>dog</string
05-02 15:51:40.652:i/system.out (3678): string>50</string
05-02 15:51:40.652:i/system.out (3678): string>3</string
05-02 15:51:40.652:i/system.out (3678): string> idiot </string
05-02 15:51:40.652:i/system.out (3678): string>25</string
05-02 15:51:40.652:i/system.out (3678):/selectallcargoinforresult
05-02 15:51:40.652:i/system.out (3678): 1

==================== Solution 1====================
The reason for the analysis is that when the thread has not finished executing, the getallinfo has already been executed, so the crraylist is 0 lines when executing for (int j = 0; J < Crraylist.size (); j + = 3). The logcat you take out is the return data after the request is executed, when the Setlistview method has already gone, so there is only one row of data. A row of data from
hashmap<string, string> temphash = new hashmap<string, string> ();
Temphash.put ("Cno", "Cno");
Temphash.put ("CNAME", "cname");
Temphash.put ("Cnum", "Cnum");
List.add (Temphash);
Use thread should be used with handler.

I'll change the code.
    private final static int   request_success = 1 ;    private final static int   request_false = 0;         private void requestdata ()     {         arraylist.clear ();         brraylist.clear ();         crraylist.clear ();                 new thread (new  Runnable ()  {                          @Override              public void run ()  {                 // todo auto-generated method stub             crraylist = soap.getwebservre ("SelectAllCargoInfor",  Arraylist, brraylist);                 message msg = new message ();                  if (Crraylist.size () >0)                  {                     msg.what =  request_success;                  }                 else                 {                 msg.what = REQUEST_FALSE; }                 //  Send messages                  mhandler.sendmessage (msg);             }         }). Start ();    }         Public handler mhandler = new handler () {           //  Receive Messages             @Override            public void handlemessage (Message &NBSP;MSG)  {               // todo  auto-generated method stub                 super.handlemessage (msg);                switch  (msg.what) {Case request_success:setlistview ();break;case  request_false://  do error handling break;default:break;}           }                   };               private void setlistview ()  {           listview.setvisibility (view.visible);           list

Execution RequestData, I can not compile, the details of their own adjustment to see, should be able to solve the problem.
You have given too few points, and Daniel has given you no answer. If we solve the problem, we will divide it.

In addition, the Java Multi-threading operation can be studied systematically. Very frequently used in work.

About Android accessing database through WebService issues

Related Article

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.