Advertisement
andyshon

refreshScreen

Dec 18th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. private void refreshScreen() {
  2.         Call<List<Course>> call = restClient.getService().getCourse();
  3.         call.enqueue(new Callback<List<Course>>() {
  4.                          @Override
  5.                          public void onResponse(Call<List<Course>> call, Response<List<Course>> response) {
  6.                              ListView lv = (ListView) findViewById(R.id.listView);
  7.  
  8.  
  9.                              ArrayList<HashMap<String, String>> courseList = new ArrayList<HashMap<String, String>>();
  10.  
  11.                              for (int i = 0; i < response.body().size(); i++) {
  12.                                  HashMap<String, String> course = new HashMap<String, String>();
  13.  
  14.                                  if (response.body().get(i).getUserId().equals(Global_config._USER_ID_CUR)) {
  15.                                      course.put("id", String.valueOf(response.body().get(i).getId()));
  16.                                      course.put("name", String.valueOf(response.body().get(i).getName()));
  17.  
  18.                                      courseList.add(course);
  19.                                  }
  20.                              }
  21.  
  22.                              lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  23.                                  @Override
  24.                                  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  25.                                      course_Id = (TextView) view.findViewById(R.id.user_Id);
  26.                                      courseId = course_Id.getText().toString();
  27.  
  28.                                      course_name = (TextView) view.findViewById(R.id.user_name);
  29.                                      courseName = course_name.getText().toString();
  30.  
  31.                                      Intent objIndent = new Intent(getApplicationContext(), CourseManagerActivity.class);
  32.                                      objIndent.putExtra("course_Id", courseId);
  33.                                      objIndent.putExtra("course_title", courseName);
  34.                                      startActivity(objIndent);
  35.                                  }
  36.                              });
  37.                              ListAdapter adapter = new SimpleAdapter(TeacherActivity.this, courseList, R.layout.view_user_entry, new String[]{"id", "name"}, new int[]{R.id.user_Id, R.id.user_name});
  38.                              lv.setAdapter(adapter);
  39.                          }
  40.  
  41.                          @Override
  42.                          public void onFailure(Call<List<Course>> call, Throwable t) {
  43.                              Toast.makeText(TeacherActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
  44.  
  45.                          }
  46.                      }
  47.         );
  48.  
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement