如何安排检查服务器的方法

时间:2016-09-22 08:09:06

标签: android android-handler

我使用baseadapter通过从Web服务获取数据来显示包含2个值的列表视图。当新数据点击服务器时,我想自动更新我的列表视图。为此,我想安排以下方法定期检查服务器的数据并更新列表。怎么做。请有人帮助我。

private void getEmployees() {
     List<Header> headers = new ArrayList<Header>();
     headers.add(new BasicHeader("Accept", "application/json"));

     EmployeeRestClient.get(MainActivity.this, "RestExample/employee", 
    headers.toArray(new Header[headers.size()]),null, 
        new JsonHttpResponseHandler() {
     @Override
     public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
     ArrayList<Employee> employeeArray = new ArrayList<Employee>();


       for (int i = 0; i < response.length(); i++) {
        try {
              employeeArray.add(new Employee(response.getJSONObject(i)));
             } catch (JSONException e) {
             e.printStackTrace();
               }
           }
     EmployeeAdapter employeeAdapter = new EmployeeAdapter(MainActivity.this, employeeArray);
       employeeList = (ListView) findViewById(R.id.list_employees);
      employeeList.setAdapter(employeeAdapter);
         }
    });
 }

0 个答案:

没有答案