2012-09-27 94 views
0

我想通過SOAP方法使用android的web服務。 這裏我的問題是,實際上我從該Web服務獲取兩個值,即「OrderNo」和「FreightRate」,我試圖在下一個屏幕的每個文本視圖框中顯示這些值,但我對文本沒有任何視圖框,無法將多個值從一個屏幕傳遞到另一個屏幕的多個文本框中android

如何實現這一概念的建議,請..

注: -我能能,如果我消耗任何一個顯示在另一個屏幕的文本視圖框只能任一個值值如「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); 


}} 

感謝您的寶貴時間!..

回答

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"); 
相關問題