Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从php页面填充spinner Android?_Android_Spinner_Populate - Fatal编程技术网

如何从php页面填充spinner Android?

如何从php页面填充spinner Android?,android,spinner,populate,Android,Spinner,Populate,我必须从这个php页面填充一个微调器: 我已经阅读了很多关于微调器和填充它们的方法的教程,但是我没有在代码中修改它们。以下是iPhone上的外观(我必须将iPhone应用程序改编成Android版本): 我必须在微调器中仅显示“vhc_名称”,并检索“vhc_登录”和“vhc_密码”以连接用户。我已经做了一个工作连接,我只需要检索好的ID来连接用户。非常感谢您的帮助。我找到了解决方案: String readFeed = readFeed(); ArrayList<Devices>

我必须从这个php页面填充一个微调器: 我已经阅读了很多关于微调器和填充它们的方法的教程,但是我没有在代码中修改它们。以下是iPhone上的外观(我必须将iPhone应用程序改编成Android版本):


我必须在微调器中仅显示“vhc_名称”,并检索“vhc_登录”和“vhc_密码”以连接用户。我已经做了一个工作连接,我只需要检索好的ID来连接用户。非常感谢您的帮助。

我找到了解决方案:

String readFeed = readFeed();

ArrayList<Devices> devices = new ArrayList<Devices>();
ArrayList<String> devicesNames = new ArrayList<String>();

try {

  JSONArray jsonArray = new JSONArray(readFeed);


  for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject jsonObject = jsonArray.getJSONObject(i);
    Devices device = new Devices();
    device.setName(jsonObject.optString("vhc_name"));
    device.setId(jsonObject.optString("vhc_login"));
    devices.add(device);
    devicesNames.add(jsonObject.optString("vhc_name"));

  }
} catch (Exception e) {
}
Spinner mySpinner = (Spinner)findViewById(R.id.myDevicesSpinner);
mySpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, devicesNames));

}
public String readFeed() {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
String userAuth = Param.getParam("user_Webbsite_Identifier").getValue();
String userPass = Param.getParam("user_Webbsite_password").getValue();

HttpGet httpGet = new HttpGet("http://sce.jelocalise.fr/mobile/ajax/getdevices.php?email="+userAuth+"&password="+userPass+"");
try {
  HttpResponse response = client.execute(httpGet);
  StatusLine statusLine = response.getStatusLine();
  int statusCode = statusLine.getStatusCode();
  if (statusCode == 200) {
    HttpEntity entity = response.getEntity();
    InputStream content = entity.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
    String line;
    while ((line = reader.readLine()) != null) {
      builder.append(line);
    }
  } else {
    Log.e(MyDevices.class.toString(), "Failed to download file");
  }
} catch (ClientProtocolException e) {
} catch (IOException e)
{
}
return builder.toString();
}