0

我正在尝试将 Web 服务中的值从一个屏幕显示到另一个屏幕,但我无法在下一个屏幕上打印这些值。

实际上我的模拟器正在运行,但只显示空屏幕

这是我的参考来源,请找到它并告诉我解决方案。

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();

       int[] ord = new int[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");

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

        x = ord.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) 
    {
    }   
    }      }

结果活动.java

 public class ResultActivity extends Activity 
 {
String str;
TextView txtv;

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

Bundle extras = getIntent().getExtras();
if(extras != null)
{   
 str = extras.getString("goto_next_page");
 }
else
{   
}

txtv = (TextView)findViewById(R.id.txtVw);
txtv.setText(str);
}}
4

3 回答 3

0

I would use AsynkTask.

And on onPostExecute I would start the activity.

That networking mixed with UI it to mess for me, does it run in Android 4 at all? - you should get an exception there with no network on UI thread or something like that, forgot the exception name. Anyway, try to separate the network and UI layers.

Also calling an asmx, I needed to se somewhere - forgot where - a param to true: isDotNet or similar the prope name.

于 2012-09-26T10:52:03.293 回答
0

use

getIntent().getStringExtra("gotonextpage", "default");

instead of

getIntent().getExtras();

in the resultActivity. Note that you have to use the same key you used to put data, to retrieve it.

于 2012-09-26T10:52:15.760 回答
0

First, you're calling your web service on the UI thread. That's a big no-no.

Second, your names don't match. You're setting the extra as "gotonextpage", but then trying to retrieve it in the second activity as "goto_next_page".

于 2012-09-26T10:53:09.020 回答