2017-06-12 7 views
0

私はユーザーIDを含むarraylistを持っています。私はdb内のidをチェックしたいと思いますし、volleyを通じてmysqlから詳細を取得し、listviewで昇順にどのように私はこれを達成することができますか?リストビューの昇順にデータを出力する

ArrayList<String> absenceids=new ArrayList<>(); 
Iterator<String> itr=absenceids.iterator(); 
while (itr.hasNext()){ 
      getdetails(itr.next()); 
     } 

マイgetdetails()メソッド:

StringRequest stringRequest = new StringRequest(Request.Method.POST,URL, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        try { 
         JSONArray jsonResponse = new JSONObject(response).getJSONArray("Android"); 

         int i=jsonResponse.length(); 

         for(int j=0;j<i;j++) { 
          JSONObject jsonChildNode = jsonResponse.getJSONObject(j); 
          String user_id = jsonChildNode.optString("uid").toString(); 
          String rollnum = jsonChildNode.optString("rollnum").toString(); 
          String name = jsonChildNode.optString("name").toString(); 
          /* MA_id.add(rollnum); 
          Collections.sort(MA_id); 
          Toast.makeText(AttendenceSave.this, MA_id.toString(), Toast.LENGTH_SHORT).show(); 
          MA_name.add(name); 
          Collections.sort(MA_name);*/ 
          HashMap<String, String> contact = new HashMap<>(); 
          contact.put("uid",user_id); 
          contact.put("rollnum",rollnum); 
          contact.put("name", name); 

          Listdetails.add(contact); 
          //CustomListAdapter2 adapter=new CustomListAdapter2(AttendenceSave.this,MA_id,MA_name); 
          ListAdapter adapter = new SimpleAdapter(AttendenceSave.this,Listdetails, R.layout.absenteeslayout, new String[]{"rollnum", "name"}, new int[]{R.id.abroll, R.id.abname}); 

          absentees_list.setAdapter(adapter); 
          Utility.setListViewHeightBasedOnChildren(absentees_list); 
+0

これまでに試したことはありますか? –

+0

あなたの努力を示してください – Piyush

+0

あなたが試したことと何が問題なのかを示すことができますか? – UltimateDevil

答えて

0

unsortedListがあなたの未ソートのリストは、IDの昇順で出力が含まれます、次の操作の後、入力されています。

Collections.sort(unsortedList,new Comparator<String>() { 
    @Override 
    public int compare(String a, String b) { 
     return a.compareTo(b); 
    } 
}); 
関連する問題