依赖Spinner使用webservice

时间:2014-01-04 05:16:55

标签: android web-services android-spinner

我使用了两个微调器,国家和州,我从网络服务。 我在第一个网络服务中获得国家/地区然后我应该将所选国家从微调器传递到第二个网络服务,我如何在Web服务中调用依赖的微调器? 举个例子, 感谢。

First Spinner

int i = 0;
        String[] stringArray = new String[List.length];



        for (i = 0; i < List.length; i++) {
        stringArray[i] = Arrays.asList(List[i].Country);
        }

        Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);


        ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, stringArray);
        adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner1.setAdapter(adapter1);

        spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
});

1 个答案:

答案 0 :(得分:1)

几天前我有同样的问题我想这会解决你的问题。

在spinner1代码

之后添加
 // here onitemselected call your second method 


@Override
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
statewebservice((String) parent.getItemAtPosition(pos));

}

对于第二个Web服务中的状态微调器

int i = 0;
String[] stringArray2 = new String[List2.length];


for (i = 0; i < personList1.length; i++) {
stringArray2[i] = Arrays.asList(List2[i].State);

}

Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, stringArray2);
            adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter2);

spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {


@Override
public void onItemSelected(final AdapterView<?> parent,
View view, final int pos1, long id) {

//************Code after selecting second spinner ***********

}

});

}