我是 self-leaner 到 android。现在我正在通过 SOAP 方法在 android eclipse 中使用 web 服务。所以我创建了两个页面。第一页由一个 edittext 和一个按钮组成第二页仅包含一个文本框。我正在创建与此网络服务完全相同的 GetBibleWordsbyKeyWord在 android eclipse 中。
这里我需要通过第一页的编辑文本框获取用户的输入,并在第二页的文本框中显示适当的文本,这正是上面的网络服务将根据用户的输入调用(显示)的内容。这些东西必须希望在单击第一页的按钮时发生。
注意:- 我试过了。它正在运行。但它只在第二页显示空白页
如何实现这个概念?
请找到我的代码以供引用
Web 服务后端类 [动态项目]
public class GetStudentInformation {
public String GetStudentInformation(String str){
return(str);
}
}
Android java类page1
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.btn);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Web_concept.class);
startActivityForResult(myIntent, 0);
}
});
}
}
Android java类page2
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText num1 = (EditText) findViewById(R.id.editT);
request.addProperty("str", Integer.valueOf(num1.getText().toString()));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,envelope);
Object result = envelope.getResponse();
System.out.println("Result : " + result.toString());
((TextView) findViewById (R.id.textView1)).setText(result.toString());
}
catch (Exception E) {
E.printStackTrace();
}
}
}
感谢您的帮助!
最佳答案
首先,按照网络服务方法中的定义,更改您对网络服务的输入
即更改行 request.addProperty("str", Integer.valueOf(num1.getText().toString()));
到
request.addProperty("str", num1.getText().toString());
当您在 webmethod
str
定义为 String 时
第二件事改变 Object result = envelope.getResponse();
到 Object result = envelope.bodyIn;
请上网查一下如何在第一页访问第二页的textView
。
我不确定。可能是不可能的。
关于android - 使用 edittext 和按钮从 android eclipse 使用 web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10738061/