0

我试图开发从肥皂网络服务中检索计数值并将它们显示到 android 模拟器。在这里,我提到了特定的 textview 意味着它不会显示在我的模拟器上。为什么这不在我的模拟器上显示。请帮我。我必须改变哪条线。这是我的安卓代码:

public class RetailerActivity extends Activity {
private static final String SOAP_ACTION = "http://xcart.com/data";
private static final String METHOD_NAME = "data";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8085/XcartLogin/services/RetailerWs?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.retrieve);
    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("&");//Result string will split & store in an array
        TextView tv = (TextView) findViewById(R.id.textView1);
       // TextView tv = new TextView(this);

        for(int i = 0; i<resultArr.length;i++){
        tv.append(resultArr[i]+"\n\n");
       }
        setContentView(tv);

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

在这里我必须写 TextView tv = new TextView(this); line 表示显示输出。但我必须输入 dis line TextView tv = (TextView) findViewById(R.id.textView1); 表示输出未显示在我的模拟器上。

4

2 回答 2

1

删除此行 setContentView(tv);。我似乎不认为setContentView()在这里使用两个是正确的。

因为您已经 setContentView(R.layout.retrieve);首先调用了 并且您已经在此处初始化了 TextView,

 TextView tv = (TextView) findViewById(R.id.textView1);

所以,

tv.append(resultArr[i]+"\n\n"); 

单独应该工作。无需重新设置tv

编辑 1

您在 xml 中的 TextView 应该是这样的。

    <TextView android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

删除其他属性,。

于 2012-08-02T06:12:22.730 回答
0

我不知道有什么append作用。

你可以写

   String s = ""
    for(int i = 0; i<resultArr.length;i++) {
            s += resultArr[i]+"\n\n";
    }
    tv.setText(s)

更好的使用StringBuilder,但以上应该工作

于 2012-08-02T06:14:00.840 回答