android - 无法在android中的单独 TextView 中显示值

标签 android web-services

我正在通过 Android 的 soap 方法使用 Web 服务。我在下一个屏幕上将来自该 Web 服务的值显示到两个单独的 TextView 中。

Web 服务在这里返回两个值。但我只能在下一屏幕的 TextView 中显示来自该 Web 服务的一个值。

但我需要在下一个屏幕上的两个单独的 TextView 框中显示这两个值.... 我怎样才能做到这一点?

建议请..

注意:- 该 Web 服务的输入值为 FromDate: 01/01/2012 和 ToDate: 07/07/2012

请找到我的引用资料

Main_WB.java

public class Main_WB extends Activity  
{
EditText edt1,edt2;
//TextView txt_1;
Button btn;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    edt1 = (EditText)findViewById(R.id.editText1);
    edt2 = (EditText)findViewById(R.id.editText2);
    btn = (Button)findViewById(R.id.button1);

    btn.setOnClickListener(new View.OnClickListener()
    {
    public void onClick(View v) 
    {
        getTMSChart(edt1.getText().toString(),edt2.getText().toString());
        Intent myint = new Intent(Main_WB.this,ResultActivity.class);
        startActivity(myint);
    }     
    });
 }

private void getTMSChart(String FromDate,String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);

 System.setProperty("http.keepAlive", "false");        
 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);        

 envelope.dotNet = true;

 String NAMESPACE = "http://tempuri.org/";
 String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
 String METHOD = "GetTMSChart";

 SoapObject request = new SoapObject(NAMESPACE, METHOD);        
 request.addProperty("FromDate", FromDate);               
 request.addProperty("ToDate", ToDate);

 envelope.setOutputSoapObject(request);
 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

 try 
 {
    androidHttpTransport.call(NAMESPACE + METHOD, envelope);
    SoapObject result = (SoapObject) envelope.bodyIn;
    SoapObject root =  (SoapObject) ((SoapObject)(result).getProperty(0)).getProperty("NewDataSet");
    int tablesCount = root.getPropertyCount();

    for (int i = 0; i < tablesCount; i++)
    {
       SoapObject table = (SoapObject) root.getProperty(i);
       int propertyCount = table.getPropertyCount();

    //   String[] ord = new String[propertyCount];
    //   String[] fre = new String[propertyCount];

    // int[] fre = new int[propertyCount];
    // int[] margin = new int[propertyCount];

    for (int j = 0; j < propertyCount; j++)
    {   

    String x,y;

    // int orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
    // int freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
    // int marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));

    String orderNo =  table.getPropertyAsString("Order_No");
    String freight = table.getAttributeAsString("Freight_Rate");


    x = orderNo.toString();
    y = freight.toString();
    Intent in = new Intent(getApplicationContext(),ResultActivity.class);

    in.putExtra("gotonextpageX",x);
    in.putExtra("gotonextpageY", y);

    startActivity(in);




    //ord[j] = orderNo;
    //  fre[j] = freightRate;
    // margin[j]= marginPercent;

    //   x = orderNo.toString();
    //   y = fre.toString();

    //   Intent myIntent = new Intent(Main_WB.this, ResultActivity.class);
    //   myIntent.putExtra("gotonextpage", x);
    //   startActivity(myIntent);


    // whatever you do with these values
          }                   
       }
    }   
    catch (Exception e) 
    {
    }   
 } }

ResultActivity.java

public class ResultActivity extends Activity 
{
String x,y;
TextView txt1,txt2;

@Override
public void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);

Bundle extras = getIntent().getExtras();

if(extras != null)
{   
    x = extras.getString("gotonextpageX");
    y = extras.getString("gotonextpageY");
}
else
{   
}
txt1 = (TextView)findViewById(R.id.txtVw);
txt2 = (TextView)findViewById(R.id.txtVw2);

txt1.setText(x);
txt2.setText(y);

}}

感谢您的宝贵时间!..

最佳答案

在这里检查一下......

public class Main_WB extends Activity {
EditText edt1, edt2;
// TextView txt_1;

Button btn;

ArrayList<String> result;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    edt1 = (EditText) findViewById(R.id.editText1);
    edt2 = (EditText) findViewById(R.id.editText2);
    btn = (Button) findViewById(R.id.button1);

    result = new ArrayList<String>();

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            result.addAll(getTMSChart(edt1.getText().toString(), edt2.getText().toString()));

            Intent in = new Intent(getApplicationContext(), ResultActivity.class);

            in.putExtra("gotonextpageX", result.get(0));
            in.putExtra("gotonextpageY", result.get(1));

            startActivity(in);
        }
    });
}

private ArrayList<String> getTMSChart(String FromDate, String ToDate) {
    // txt_1 = (TextView)findViewById(R.id.textView1);

    System.setProperty("http.keepAlive", "false");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.dotNet = true;

    String NAMESPACE = "http://tempuri.org/";
    String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
    String METHOD = "GetTMSChart";

    SoapObject request = new SoapObject(NAMESPACE, METHOD);
    request.addProperty("FromDate", FromDate);
    request.addProperty("ToDate", ToDate);

    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    String x = "", y = "";

    ArrayList<String> stringResult = new ArrayList<String>();

    try {
        androidHttpTransport.call(NAMESPACE + METHOD, envelope);
        SoapObject result = (SoapObject) envelope.bodyIn;
        SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
        int tablesCount = root.getPropertyCount();

        for (int i = 0; i < tablesCount; i++) {
            SoapObject table = (SoapObject) root.getProperty(i);
            int propertyCount = table.getPropertyCount();

            for (int j = 0; j < propertyCount; j++) {

                stringResult.add(table.getPropertyAsString("Order_No").toString());
                stringResult.add(table.getPropertyAsString("Freight_Rate").toString());
            }
        }
    } catch (Exception e) {
    }

    return stringResult;

}
}

并且不要更改您的第二个类,这一定有效。

关于android - 无法在android中的单独 TextView 中显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667840/

相关文章:

java - 从 SOAP wsdl 生成客户端 jar

android - 如何查找通知 ID?

android - 在 Eclipse 中更新 sdk rev.21 后无法设置 Android 目标

asp.net - 从 ASP.net Web 服务返回大量数据时有哪些好的做法?

java - Glassfish 4.1 LogFactory 和 WSSElementFactory NoClassDefFoundError

iOS 应用程序在调用 Web 服务最佳实践之前确保互联网可用

c# - 如何在 https (ssl) channel 上通过服务堆栈运行 RESTful web 服务

android - Android-与线程相关的崩溃

java - 通过WIFI从SQL服务器检索数据

java - 在嵌套方法中更新变量不会全局更新它