スピナーに Web サービス データ (XML 解析) を入力する必要があります。「ID」と「名前」のような 2 つの属性が含まれています。コードは次のとおりです。
try {
ArrayList<String> listdata = new ArrayList<String>();
URL url = new URL(
"http://10.0.2.2/WebService/Service.asmx/GetService");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("Table");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element providerID = (Element) node;
NodeList providerIDlist = providerID.getElementsByTagName("id");
Element providerIDelement = (Element) providerIDlist.item(0);
providerIDlist = providerIDelement.getChildNodes();
MProviderIDL = providerIDlist.item(0).getNodeValue();
//mprovider.put("MproviderID", MProviderIDL.toString());
listdata.add(MProviderIDL);
Element providerName = (Element) node;
NodeList providerNamelist = providerName.getElementsByTagName("value");
Element prividerNameElement = (Element) providerNamelist.item(0);
providerNamelist = prividerNameElement.getChildNodes();
//AddImg[i].setTag(((Node) AdvImglist.item(0)).getNodeValue());
MProviderNameL = providerNamelist.item(0).getNodeValue();
//mprovider.put("MproviderName", MProviderNameL.toString());
listdata.add(MProviderNameL);
}
Spinner spinMProvider=(Spinner)findViewById(R.id.spinMProvider);
ArrayAdapter < String > adapter = new ArrayAdapter < String > (this,
android.R.layout.simple_list_item_1,listdata);
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
spinMobileProvider.setAdapter(adapter);
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
値をデータベースに送信..
private void Send(View v,String Url) {
HttpPost postMethod=new HttpPost(Url);
List<NameValuePair> regParams=new ArrayList<NameValuePair>();
DefaultHttpClient hc=new DefaultHttpClient();
regParams.add(new BasicNameValuePair("_fname",edtFname.getText().toString()));
regParams.add(new BasicNameValuePair("_lname",edtLname.getText().toString()));
regParams.add(new BasicNameValuePair("_email",edtEmail.getText().toString()));
regParams.add(new BasicNameValuePair("_password",edtPassword.getText().toString()));
regParams.add(new BasicNameValuePair("_address",edtAddress.getText().toString()));
regParams.add(new BasicNameValuePair("Provider", Integer.toString(spinMProvider.getSelectedItemPosition())));
私のXMLデータ...
<Table diffgr:id="Table4" msdata:rowOrder="3">
<id>11</id>
<value>Cellular South</value>
</Table>
<Table diffgr:id="Table5" msdata:rowOrder="4">
<id>10</id>
<value>Cricket</value>
</Table>
<Table diffgr:id="Table6" msdata:rowOrder="5">
<id>4</id>
<value>Sprint NexTel</value>
</Table>
そして、このように出力して……
スピナー リストに名前を表示し、特定の ID をデータベースに渡す必要があります。テキストのバックエンドに ID を取得する方法は?