2017-03-14 2 views
-1

발리 라이브러리를 사용하여 ListView에 JSON 데이터를 표시 할 수 없습니다.JSON 데이터를 ListView에 표시 할 수 없습니까?

요금 클래스

public class Fee extends Fragment /*implements View.OnClickListener */ { 

    LinearLayout receipt1, receipt2, receipt3, receipt4; 
    LinearLayout receipt1detail, receipt2detail, receipt3detail, receipt4detail; 


    TextView statustextView; 

    ListView listView; 
    List<StudentFeeInformation> yourData = new ArrayList<StudentFeeInformation>(); 
    public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees"; 
    // public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees?ID=111"; 
    String master_id; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.student_fees_listview, container, false); 
     setHasOptionsMenu(true); 
     // receipt1 = (LinearLayout) view.findViewById(R.id.linear_receipt1_fee); 
     // receipt2 = (LinearLayout) view.findViewById(R.id.linear_receipt2_fee); 
     // receipt3 = (LinearLayout) view.findViewById(R.id.linear_receipt3_fee); 
     // receipt4 = (LinearLayout) view.findViewById(R.id.linear_receipt4_fee); 

     // receipt1detail = (LinearLayout) view.findViewById(R.id.receipt1_fee); 
     // receipt2detail = (LinearLayout) view.findViewById(R.id.receipt2_fee); 
     // receipt3detail = (LinearLayout) view.findViewById(R.id.receipt3_fee); 
     // receipt4detail = (LinearLayout) view.findViewById(R.id.receipt4_fee); 

     // receipt1.setOnClickListener(this); 
     // receipt2.setOnClickListener(this); 
     // receipt3.setOnClickListener(this); 
     // receipt4.setOnClickListener(this); 


     // receipt1detail.setVisibility(View.VISIBLE); 
     // receipt2detail.setVisibility(View.GONE); 
     // receipt3detail.setVisibility(View.GONE); 
     // receipt4detail.setVisibility(View.GONE); 

     statustextView = (TextView) view.findViewById(R.id.student_profile_fee_status); 


     SessionManagement sessionManagement = new SessionManagement(getContext()); 
     master_id = sessionManagement.getMasterId(); 

     listView = (ListView) view.findViewById(R.id.list_student_fees); 
     CustomFeeListStudentAdapter customFeeListStudentAdapter = new CustomFeeListStudentAdapter(getContext(), R.layout.fragment_fee, yourData); 
     listView.setAdapter(customFeeListStudentAdapter); 


     getUsersListData(); 

     return view; 
    } 


    StudentFeeInformation studentFeeInformation; 


    private void getUsersListData() { 
     String URL = Navigation_URL + "?id=" + master_id; 
     StringRequest stringRequest = new StringRequest(Request.Method.GET, URL, 
       new Response.Listener<String>() { 
        @Override 
        public void onResponse(String response) { 
         try { 

          JSONArray jArray = new JSONArray(response); 
          studentFeeInformation = new StudentFeeInformation(); 
          for (int i = 0; i < jArray.length(); i++) { 

           JSONObject jsonObject = jArray.getJSONObject(i); 
           studentFeeInformation.Status = jsonObject.getString("Status"); 
           System.out.println("This is Good"); 
           System.out.print(studentFeeInformation.Status); 
          } 


         } catch (JSONException e) { 

          System.out.println("This is not good"); 

          e.printStackTrace(); 

         } 

        } 

       }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       // Toast.makeText(view.Fee.this, error.toString(), Toast.LENGTH_LONG).show(); 

      } 
     }) { 

      @Override 
      public Map<String, String> getHeaders() throws AuthFailureError { 
       Map<String, String> headers = new HashMap<String, String>(); 
       return headers; 
      } 

     }; 

     RequestQueue requestQueue = Volley.newRequestQueue(getContext()); 
     requestQueue.add(stringRequest); 


    } 
    } 

StudentFeeInformation

public class StudentFeeInformation implements Serializable { 
    public String Status; 

    public String getStatus() { 
     return Status; 
    } 

    public void setStatus(String status) { 
     Status = status; 
    } 
} 

CustomFeeListStudentAdapter

public class CustomFeeListStudentAdapter extends ArrayAdapter<StudentFeeInformation> { 

    private List<StudentFeeInformation> items; 

    public CustomFeeListStudentAdapter(Context context, int resource) { 
     super(context, resource); 
    } 

    public CustomFeeListStudentAdapter(Context context, int resource, List<StudentFeeInformation> items) { 
     super(context, resource, items); 
    } 


    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     View v = convertView; 

     TextView tt = null; 


     if (v == null) { 
      LayoutInflater vi; 
      vi = LayoutInflater.from(getContext()); 
      v = vi.inflate(R.layout.fragment_fee, null); 

      tt = (TextView) v.findViewById(R.id.student_profile_fee_status); 

     } 

     StudentFeeInformation p = items.get(position); 

     if (p != null) { 

      if (tt != null) { 
       tt.setText("" + p.getStatus()); 
      } 

     } 


     return v; 

    } 


} 

student_fees_listview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#2E353D" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:layout_gravity="center_horizontal" 
      android:orientation="horizontal"> 

      <ImageView 
       android:layout_width="30dp" 
       android:layout_height="match_parent" 
       android:padding="3dp" 
       android:src="@mipmap/fee" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:layout_marginLeft="8dp" 
       android:text="Fees" 
       android:textColor="#fff" 
       android:textSize="17dp" 
       android:textStyle="bold" /> 

     </LinearLayout> 
    </LinearLayout> 


    <ListView 
     android:id="@+id/list_student_fees" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     /> 


</LinearLayout> 

fragment_fee

<LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:background="#DCE2E8" 
          android:orientation="horizontal" 
          android:padding="5dp"> 

          <TextView 
           android:layout_width="0dp" 
           android:layout_height="wrap_content" 
           android:layout_weight="1" 
           android:paddingLeft="70dp" 
           android:text="Status" 
           android:textSize="10dp" 
           android:textStyle="bold" /> 

          <TextView 
           android:id="@+id/student_profile_fee_status" 
           android:layout_width="0dp" 
           android:layout_height="wrap_content" 
           android:layout_weight="1" 
           android:paddingLeft="70dp" 
           android:text="Paid" 
           android:textColor="#108B89" 
           android:textSize="10dp" 
           android:textStyle="bold" /> 

         </LinearLayout> 

JSON리스트 뷰는 JSON 데이터로 채워 할 수있는 방법을

[ 
    { 
    "MasterID": "E0017", 
    "StdID": 111, 
    "Status": "P", 
    "AmountPaid": 6645, 
    "Class": 8, 
    "DateOfReciept": "2017-01-01T00:00:00", 
    "Description": "[{\"des\":\"Admission\",\"Amount\":300},{\"des\":\"Monthly Fee\",\"Amount\":5400},{\"des\":\"Exam Fee\",\"Amount\":200},{\"des\":\"Extra Charge\",\"Amount\":400},{\"des\":\"Late Charge\",\"Amount\":345}]", 
    "RecieptNo": 1011, 
    "NAME": "Uzumaki Naruto", 
    "recivedDate": "2017-03-10T00:00:00", 
    "reciever": "Cynthia Irwin" 
    }, 
    { 
    "MasterID": "E0017", 
    "StdID": 111, 
    "Status": "U", 
    "AmountPaid": 5600, 
    "Class": 8, 
    "DateOfReciept": "2017-03-01T00:00:00", 
    "Description": "[{\"des\":\"Exam Fee\",\"Amount\":200},{\"des\":\"Monthly Fee\",\"Amount\":5400}]", 
    "RecieptNo": 1012, 
    "NAME": "Uzumaki Naruto", 
    "recivedDate": "2017-03-06T00:00:00", 
    "reciever": "Cynthia Irwin" 
    } 
] 

? 나에게 01 제시해주십시오내가 잘못하고있다.

답변

1

요금 클래스

public class Fee extends Fragment /*implements View.OnClickListener */ { 

     LinearLayout receipt1, receipt2, receipt3, receipt4; 
     LinearLayout receipt1detail, receipt2detail, receipt3detail, receipt4detail; 


     TextView statustextView; 

     ListView listView; 
     List<StudentFeeInformation> yourData = new ArrayList<StudentFeeInformation>(); 
     public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees"; 
     // public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees?ID=111"; 
     String master_id; 
     StudentFeeInformation studentFeeInformation; 


     @Nullable 
     @Override 
     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 

      View view = inflater.inflate(R.layout.student_fees_listview, container, false); 
      setHasOptionsMenu(true); 

      statustextView = (TextView) view.findViewById(R.id.student_profile_fee_status); 


      SessionManagement sessionManagement = new SessionManagement(getContext()); 
      master_id = sessionManagement.getMasterId(); 

      listView = (ListView) view.findViewById(R.id.list_student_fees); 
      //CustomFeeListStudentAdapter customFeeListStudentAdapter = new CustomFeeListStudentAdapter(getContext(), R.layout.fragment_fee, yourData); 
      //listView.setAdapter(customFeeListStudentAdapter); 


      getUsersListData(); 

      return view; 
     } 

     private void getUsersListData() { 
      String URL = Navigation_URL + "?id=" + master_id; 
      StringRequest stringRequest = new StringRequest(Request.Method.GET, URL, 
        new Response.Listener<String>() { 
         @Override 
         public void onResponse(String response) { 
          try { 

           ArrayList<StudentFeeInformation> student_list=new ArrayList<>(); 
           JSONArray jArray = new JSONArray(response); 

           for (int i = 0; i < jArray.length(); i++) { 

            JSONObject jsonObject = jArray.getJSONObject(i); 
            String status = jsonObject.getString("Status"); 
            System.out.println("status:"+status); 
            student_list.add(new StudentFeeInformation(status)); 
           } 

           System.out.println("student_list size:"+student_list.size()); 
           CustomFeeListStudentAdapter customFeeListStudentAdapter = new CustomFeeListStudentAdapter(getActivity(), student_list); 
           listView.setAdapter(customFeeListStudentAdapter); 
          } catch (JSONException e) { 
           System.out.println("This is not good"); 
           e.printStackTrace(); 
          } 
         } 
        }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        // Toast.makeText(view.Fee.this, error.toString(), Toast.LENGTH_LONG).show(); 

       } 
      }) { 

       @Override 
       public Map<String, String> getHeaders() throws AuthFailureError { 
        Map<String, String> headers = new HashMap<String, String>(); 
        return headers; 
       } 

      }; 

      RequestQueue requestQueue = Volley.newRequestQueue(getContext()); 
      requestQueue.add(stringRequest); 
     } 
     } 

StudentFeeInformation 모델 클래스 :

public class StudentFeeInformation implements Serializable { 
     public String Status; 


     public StudentFeeInformation(String status) { 
      Status = status; 
     } 

     public String getStatus() { 
      return Status; 
     } 

     public void setStatus(String status) { 
      Status = status; 
     } 
    } 

CustomFeeListStudentAdapter : 난 당신의 지점을 받고 있지 않다

public class CustomFeeListStudentAdapter extends BaseAdapter { 

     Context mContext; 

     ArrayList<StudentFeeInformation>student_list; 
     String TAG="HomeTab_adapter"; 
     public CustomFeeListStudentAdapter(Context mContext, ArrayList<StudentFeeInformation> student_list) { 
      super(); 
      this.mContext = mContext; 
      this.student_list=student_list; 
     } 

     @Override 
     public int getCount() { 
      return student_list.size(); 
     } 

     @Override 
     public Object getItem(int arg0) { 
      return arg0; 
     } 

     @Override 
     public long getItemId(int arg0) { 
      return arg0; 
     } 

     @Override 
     public View getView(final int postion, View convertView, ViewGroup parent) 
     { 
      final Holder viewHolder; 
      if(convertView==null) 
      { 
       // inflate the layout 
       LayoutInflater inflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       convertView=inflater.inflate(R.layout.R.layout.fragment_fee, parent, false); 

       // well set up the ViewHolder 
       viewHolder = new Holder(); 
       viewHolder.student_profile_fee_status = (TextView)convertView.findViewById(R.id.student_profile_fee_status); 

      } 
      else{ 
       // we've just avoided calling findViewById() on resource everytime 
       // just use the viewHolder 
       viewHolder = (Holder) convertView.getTag(); 
      } 

      viewHolder.student_profile_fee_status.setText(student_list.get(postion).getStatus()); 


      convertView.setTag(viewHolder); 
      return convertView; 
     } 

     class Holder{ 
      TextView student_profile_fee_status; 

     } 
    } 
+0

에 알려 주시기 바랍니다 수 있습니다 여기에 studentFeeInformation = new StudentF eeInformation (매개 변수 필요); – seon

+0

@seon 그 문장을 제거합니다 ... 필요 없음 .. 업데이트 된 코드를 확인하십시오 – user2025187

+0

Logcat에서 값을 얻었지만 값이보기에 표시되지 않습니다 – seon

1

studentFeeInformationyourData 목록에 추가하지 않은 것처럼 보입니다. 생성 된 studentFeeInformationgetUsersListData()에 추가하고 for 루프가 완료되면 notifyDataSetChanged()으로 전화하십시오.

+0

, 당신이 매개 변수는 무엇을해야 상세 – seon