无法将多个值从一个屏幕传递到android中另一个屏幕的多个textview框

时间:2012-09-27 09:48:02

标签: android web-services textview

我试图通过SOAP方法从android使用Web服务。 这里我的问题是,实际上我从该Web服务获得两个值,即“OrderNo”和“FreightRate”,我试图在下一个屏幕的每个文本视图框中显示这些值,但我在文本视图中什么都没有盒,

如何实现这个概念?建议请...

注意: - 如果我使用“orderNo”或“FreightRate”之类的任何值,我只能在另一个屏幕的文本视图框中显示任何一个值。但无法在另一个屏幕的单独文本视图框中同时显示两个值。

请找我的参考资料

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("gotonextpage",x);
    in.putExtra("gotonextpage", 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("gotonextpage");
    y = extras.getString("gotonextpage");
}
else
{   
}
txt1 = (TextView)findViewById(R.id.txtVw);
txt2 = (TextView)findViewById(R.id.txtVw2);
txt1.setText(x);
txt2.setText(y);


}}

感谢您宝贵的时间!..

1 个答案:

答案 0 :(得分:0)

也许这不是您的问题,但是,在您的主要活动中,您尝试使用您的意图发送这两个值,但是您使用相同的密钥添加它们。在您的示例中,您总是发送值y,因为您正在覆盖x值。

in.putExtra("gotonextpage",x);
in.putExtra("gotonextpage", y);

如果我正确理解您的问题,您需要为您的值使用两个不同的密钥,在使用意图发送它们并提取它们时。

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

x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");

另一种方法是

x = getIntent().getStringExtra("gotonextpageX");
y = getIntent().getStringExtra("gotonextpageY");