private void updateScore(String username, int score) { String url = "http://203.151.92.187:8080/updateAssignmentScore"; String param = "sessionId=" + URLEncoder.encode(SingletonID.getInstance().getSessionId()) + "&courseId=" + URLEncoder.encode(courseId) + "&username="******"&title=" + URLEncoder.encode(title) + "&score=" + URLEncoder.encode(String.valueOf(score)); String result = "Fail"; try { HttpPostConnection httpPostConnection = new HttpPostConnection(); httpPostConnection.execute(url, param); String strJson = httpPostConnection.get(); JSONObject jsonObject = new JSONObject(strJson); result = jsonObject.getString("status"); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show(); }
private void createList() { stdName = new ArrayList<String>(); stdUser = new ArrayList<String>(); String url = "http://203.151.92.187:8080/viewEnrolledStudents"; String param = "courseId=" + URLEncoder.encode(courseId); try { HttpPostConnection httpPostConnection = new HttpPostConnection(); httpPostConnection.execute(url, param); String strJson = httpPostConnection.get(); JSONArray jsonArray = new JSONArray(strJson); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String stdId = jsonObject.getString("studentId"); String name = jsonObject.getString("firstName") + " " + jsonObject.getString("lastName"); String user = jsonObject.getString("username"); Log.i("Test", user + " " + " " + stdId + " " + name); stdName.add(stdId + " " + name); stdUser.add(user); } } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_layout, stdName); final ListView listview = (ListView) findViewById(R.id.listView); listview.setAdapter(adapter); listview.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { show(stdUser.get(position)); } }); }