用肥皂通话的Andr​​oid的ListView [英] android listview using soap calling

查看:82
本文介绍了用肥皂通话的Andr​​oid的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我不得不开发在Android中使用肥皂calling.here 1的ListView应用我希望运行应用程序意味着OrderID和被here.here显示的状态,我必须从列表中单击任一阶表示状态会显示下一个活动。

但OrderID和状态显示在列表视图successfully..but这里遇到了一些问题...... OrderID和状态显示格式如下:

  1
---------
F2
----------
Q3
----------
P
-----------

但我希望以显示如下格式:

  1μF
---------
2 Q
---------
3 P
---------

这是我的安卓code

 公共类RetailerActivity延伸活动{
ListView控件列表;
私有静态最后弦乐SOAP_ACTION =htt​​p://xcart.com/customerData1;
私有静态最后弦乐METHOD_NAME =customerData1;
私有静态最后弦乐NAMESPACE =htt​​p://xcart.com;
私有静态最终字符串URL =htt​​p://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl;
私有静态最后弦乐KEY_STATUS =身份;/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);    SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);    envelope.setOutputSoapObject(请求);    HttpTransportSE HT =新HttpTransportSE(URL);
    尝试{
        ht.call(SOAP_ACTION,信封);
        SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();
        SoapPrimitive S =响应;
        字符串str = s.toString();
        串resultArr [] = str.split(与&);
        名单=(ListView控件)findViewById(R.id.list);
        list.setAdapter(新ArrayAdapter(这一点,android.R.layout.simple_list_item_1,resultArr));
        list.setOnItemClickListener(新OnItemClickListener(){            @覆盖
            公共无效onItemClick(适配器视图<>母公司,观景,
                    INT位置,长的id){                字符串s2 = getIntent()getStringExtra(身份)。
                //开始新意图
                在意向=新意图(getApplicationContext(),SingleMenuItemActivity.class);                 in.putExtra(KEY_STATUS,S2);
                 startActivity(在);            }
        });
    }
    赶上(例外五){
        e.printStackTrace();
    }
}}

这是我的 web服务code

 公共类RetailerWs {
公共字符串customerData1(){
串customerInfo =;
尝试{
的Class.forName(com.mysql.jdbc.Driver);
连接CON =的DriverManager.getConnection(JDBC的:mysql://本地主机:3306 / xcart-432pro,根,);
  //查找客户信息,其中客户ID为最大
。preparedStatement声明= CON prepareStatement(SELECT * FROM xcart_orders);
ResultSet的结果= Statement.executeQuery的(); 而(result.next()){
customerInfo = customerInfo + result.getString(订单ID)+&放大器; + result.getString(身份);
  //这里与&被添加到返回字符串。这有助于在分裂Android应用程序字符串
 }
 } 赶上(例外EXC){
 的System.out.println(exc.getMessage());
 }返回customerInfo;
 } }

这是我的main.xml文件:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直> < ListView控件
    机器人:ID =@ + ID /列表
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:分=#b5b5b5
    机器人:dividerHeight =1DP
    机器人:listSelector =@绘制/ list_selector/> < / LinearLayout中>


解决方案

更改Web服务code线:

  customerInfo = customerInfo + result.getString(订单ID)+&放大器; + result.getString(身份);

  customerInfo = customerInfo
    + result.getString(订单ID)
    +//这从分离状态的订单ID
    + result.getString(身份)
    +与& ; //这是你在你的Andr​​oid code分流

所以,为您的样品输入

  1μF
2 Q
3 P

您现在可以生成字符串1 F&安培; 2 Q和3 P,而不是1安培; F2和放大器; Q3&安培; P

在这之后,我建议你去思考一些更好的方式来你的组件之间传递数据。

Hi i have to develop one listview app in android using soap calling.here i wish to run the app means the orderid and status is displayed here.here i have to click any order from list means the status is displayed next activity.

But the orderid and status is displayed on listview successfully..but here faced some problem...the orderid and status is displayed following format:

1
---------
F2
----------
Q3
----------
P
-----------

But i wish to display below format:

1 F
---------
2 Q
---------
3 P
---------

This is my android code:

public class RetailerActivity extends Activity {
ListView list;
private static final String SOAP_ACTION = "http://xcart.com/customerData1";
private static final String METHOD_NAME = "customerData1";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl";
private static final String KEY_STATUS = "status";



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.setOutputSoapObject(request);

    HttpTransportSE ht = new HttpTransportSE(URL);
    try {
        ht.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        SoapPrimitive s = response;
        String str = s.toString();
        String resultArr[] = str.split("&");
        list=(ListView)findViewById(R.id.list);


        list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,resultArr));
        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                String s2= getIntent().getStringExtra("status");


                // Starting new intent
                Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);

                 in.putExtra(KEY_STATUS, s2);


                 startActivity(in);                 

            }
        });     
    }


    catch (Exception e) {
        e.printStackTrace();
    }
}

}

This is my webservice code:

public class RetailerWs {
public String customerData1(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
  //Find customer information where the customer ID is maximum
PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_orders");
ResultSet result = statement.executeQuery();

 while(result.next()){
customerInfo = customerInfo + result.getString("orderid") + "&" + result.getString("status");
  //Here "&"s are added to the return string. This is help to split the string in Android application
 }
 }

 catch(Exception exc){
 System.out.println(exc.getMessage());
 }

return customerInfo;
 }

 }

this is my main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

 <ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="#b5b5b5"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector" />

 </LinearLayout>

解决方案

Change your webservice code line:

customerInfo = customerInfo + result.getString("orderid") + "&" + result.getString("status");

to:

customerInfo = customerInfo 
    + result.getString("orderid") 
    + " "   // this to separate order id from status
    + result.getString("status") 
    + "&" ; // this is where you split in your android code

So, for your sample input

1 F
2 Q
3 P

you now generate the string "1 F&2 Q&3 P" instead of "1&F2&Q3&P".

After that, I suggest you to think some better way to pass data between your components.

这篇关于用肥皂通话的Andr​​oid的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆