在List项中动态添加线性布局?

时间:2017-05-12 06:51:53

标签: android android-layout android-linearlayout

我无法在列表中使用List,所以我跳转到ListItems中添加要添加的动态线性布局。我想显示包含许多 textview 的列表并在textview下面我想显示另一个listview。所以我切换到在父列表中动态添加线性布局。

XML

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/linear_receipt1_fee"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#008b8b"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/student_profile_fee_ReceiptIssuedDate"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:padding="6dp"
                    android:text="Date"
                    android:textColor="#fff"
                    android:textStyle="bold" />

                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#FFFFFF" />

                <TextView
                    android:id="@+id/student_profile_fee_ReceiptIssuedNumber"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:padding="6dp"
                    android:text="Receipt number"
                    android:textColor="#fff"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/receipt1_fee"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

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

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_horizontal"
                        android:padding="5dp"
                        android:text="Description"
                        android:textSize="12dp"
                        android:textStyle="bold" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_horizontal"
                        android:padding="5dp"
                        android:text="Amount (Nrs) "
                        android:textSize="12dp"
                        android:textStyle="bold">


                    </TextView>

                </LinearLayout>

**how can this linear layout be repeatedly added inside the list items**
                <LinearLayout
                    android:id="@+id/student_profile_fee_linearlayout1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/student_profile_fee_description"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left|center"
                        android:paddingLeft="70dp"
                        android:paddingTop="10dp"
                        android:text="Sports"
                        android:textSize="10dp" />

                    <TextView
                        android:id="@+id/student_profile_fee_amount"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left|center"
                        android:paddingLeft="70dp"
                        android:paddingTop="10dp"
                        android:text="1000"
                        android:textSize="10dp" />
                </LinearLayout>    **end here **
 <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#C5CED1" />

                <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="Total"
                        android:textSize="10dp"
                        android:textStyle="bold" />

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

                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#C5CED1" />

                <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>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#C5CED1" />


                <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="Received Date"
                        android:textSize="10dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/student_profile_fee_FeeReceiptDate"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:paddingLeft="70dp"
                        android:text="9 March,2017"
                        android:textSize="10dp"
                        android:textStyle="bold" />

                </LinearLayout>
            </LinearLayout>

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#fff" />
   </LinearLayout>

CustomFeeListStudentAdapter

public class CustomFeeListStudentAdapter extends BaseAdapter {
    LinearLayout reciptViewDynamic;

    Context mContext;
    Fee fee = new Fee();

    ArrayList<StudentFeeInformation> student_list;


    LinearLayout linearLayout;

    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() {

        System.out.println(student_list.size());
        return student_list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return student_list.get(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.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);
            viewHolder.student_profile_ReceiptIssuedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedDate);
            viewHolder.student_profile_ReceiptIssuedNumber = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedNumber);
            viewHolder.student_profile_FeeReceivedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_FeeReceiptDate);
            // viewHolder.student_profile_Fee_Amount = (TextView) convertView.findViewById(R.id.student_profile_fee_amount);
            // viewHolder.student_profile_Fee_Description = (TextView) convertView.findViewById(R.id.student_profile_fee_description);


            //added code
            viewHolder.receiptLinearLayout = (LinearLayout) convertView.findViewById(R.id.recipt_layout);


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


        Log.d(TAG, "@@ postion:" + postion + " getFeeDescription" + student_list.get(postion).getFeeDescription());
        Log.d(TAG, "@@ postion:" + postion + " getAmount" + student_list.get(postion).getAmount());

        viewHolder.student_profile_fee_status.setText(student_list.get(postion).getStatus());
        viewHolder.student_profile_ReceiptIssuedDate.setText(student_list.get(postion).getReceiptIssuedDate());
        viewHolder.student_profile_ReceiptIssuedNumber.setText(student_list.get(postion).getReceiptIssuedNumber());
        viewHolder.student_profile_FeeReceivedDate.setText(student_list.get(postion).getFeeReceivedDate());
        //  viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());
        // viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());


        //added code
        for (int i = 0; i < 1; i++) {

            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //   reciptViewDynamic = (LinearLayout) inflater.inflate(R.layout.layout_bil_info, null);


            reciptViewDynamic = (LinearLayout) inflater.inflate(R.layout.layout_bil_info, parent, false);
            viewHolder.student_profile_Fee_Amount = (TextView) reciptViewDynamic.findViewById(R.id.student_profile_fee_amount);
            viewHolder.student_profile_Fee_Description = (TextView) reciptViewDynamic.findViewById(R.id.student_profile_fee_description);
            viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());
            viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());


            viewHolder.receiptLinearLayout.addView(reciptViewDynamic);
            viewHolder.receiptLinearLayout.removeAllViews();


        }


        convertView.setTag(viewHolder);
        return convertView;
    }

    class Holder {
        TextView student_profile_fee_status;
        TextView student_profile_ReceiptIssuedDate;
        TextView student_profile_ReceiptIssuedNumber;
        TextView student_profile_FeeReceivedDate;
        TextView student_profile_Fee_Amount;
        TextView student_profile_Fee_Description;
        LinearLayout receiptLinearLayout;


    }


}

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

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


    TextView statustextView, feedescription, feeamount;
    ListView listViewfees, listviewfeedetail;
    List<StudentFeeInformation> yourData = new ArrayList<StudentFeeInformation>();

    public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees";
    String Amount;
    String Descriptionlist, status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate;
    ArrayList arrayList = new ArrayList();
    String master_id;

    LinearLayout linearLayout;
    TextView textView;


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


        View view = inflater.inflate(R.layout.student_fees_listview, container, false);
        inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // view1 = inflater.inflate(R.layout.student_fees_description_data, null);


        setHasOptionsMenu(true);
        receipt1 = (LinearLayout) view.findViewById(R.id.linear_receipt1_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();
        listViewfees = (ListView) view.findViewById(R.id.list_student_fees);
        // listviewfeedetail = (ListView) view.findViewById(R.id.listtest);

        //  DescriptionAmount = (LinearLayout) view.findViewById(R.id.student_profile_fee_linearlayout1);
        // DescriptionAmount.addView(view);


        linearLayout = (LinearLayout) view.findViewById(R.id.student_profile_fee_linearlayout1);
        //   v = (LinearLayout)( view.inflate(getContext(), R.layout.student_fees_description_data, null));
        //  linearLayout.addView(view);

        feedescription = (TextView) view.findViewById(R.id.student_profile_fee_description);
        feeamount = (TextView) view.findViewById(R.id.student_profile_fee_amount);


        textView = (TextView) view.findViewById(R.id.student_profile_fee_amount);


        getUsersListData();


        return view;
    }


    private void getUsersListData() {


        String URL = Navigation_URL + "?id=" + master_id + "&fromDate=" + "&toDate=";
        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<>();
                            ArrayList<ArrayList> student_list_description = new ArrayList<>();


                            JSONArray jArray = new JSONArray(response);

                            //  studentFeeInformation = new StudentFeeInformation(response);
                            for (int i = 0; i < jArray.length(); i++) {
                                JSONObject jsonObject = jArray.getJSONObject(i);

                                status = jsonObject.getString("Status");
                                DateofReceiptIssued = jsonObject.getString("DateOfReciept").substring(0, 10);
                                ReceiptNumber = jsonObject.getString("RecieptNo");
                                FeeReceivedDate = jsonObject.getString("recivedDate").substring(0, 10);


                                String Description = jsonObject.getString("Description");
                                JSONArray jArray1 = new JSONArray(Description);

                                //
                                for (int j = 0; j < jArray1.length(); j++) {


                                    JSONObject jsonObjectinner = jArray1.getJSONObject(j);
                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");
                                    arrayList.add(Descriptionlist);
                                    Log.d("ArrayList", String.valueOf(arrayList));
                                    student_list.add(new StudentFeeInformation(Descriptionlist, Amount));

                                }
                                student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));


                            }

                            System.out.println("student_list size:" + student_list.size());
                            CustomFeeListStudentAdapter customFeeListStudentAdapter = new CustomFeeListStudentAdapter(getActivity(), student_list);

                            listViewfees.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);


    }


    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Auto-generated method stub
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.dashboard, menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // handle item selection
        switch (item.getItemId()) {
            case R.id.action_settings:
                // do s.th.
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
  

如何在ListItem中动态添加线性布局?

2 个答案:

答案 0 :(得分:0)

<强> CustomFeeListStudentAdapter

public class CustomFeeListStudentAdapter extends BaseAdapter {
    LinearLayout reciptViewDynamic;

    Context mContext;
    Fee fee = new Fee();

    ArrayList<StudentFeeInformation> student_list;


    LinearLayout linearLayout;

    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() {

        System.out.println(student_list.size());
        return student_list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return student_list.get(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.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);
            viewHolder.student_profile_ReceiptIssuedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedDate);
            viewHolder.student_profile_ReceiptIssuedNumber = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedNumber);
            viewHolder.student_profile_FeeReceivedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_FeeReceiptDate);
            // viewHolder.student_profile_Fee_Amount = (TextView) convertView.findViewById(R.id.student_profile_fee_amount);
            // viewHolder.student_profile_Fee_Description = (TextView) convertView.findViewById(R.id.student_profile_fee_description);


            //added code
            viewHolder.receiptLinearLayout = (LinearLayout) convertView.findViewById(R.id.recipt_layout);


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


        Log.d(TAG, "@@ postion:" + postion + " getFeeDescription" + student_list.get(postion).getFeeDescription());
        Log.d(TAG, "@@ postion:" + postion + " getAmount" + student_list.get(postion).getAmount());

        viewHolder.student_profile_fee_status.setText(student_list.get(postion).getStatus());
        viewHolder.student_profile_ReceiptIssuedDate.setText(student_list.get(postion).getReceiptIssuedDate());
        viewHolder.student_profile_ReceiptIssuedNumber.setText(student_list.get(postion).getReceiptIssuedNumber());
        viewHolder.student_profile_FeeReceivedDate.setText(student_list.get(postion).getFeeReceivedDate());
        //  viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());
        // viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());


        Fee fee=new Fee();
        fee.getUsersListData();


        //added code
        for (int i = 0; i < ; i++) {

            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //   reciptViewDynamic = (LinearLayout) inflater.inflate(R.layout.layout_bil_info, null);


            reciptViewDynamic = (LinearLayout) inflater.inflate(R.layout.layout_bil_info, parent, false);
            viewHolder.student_profile_Fee_Amount = (TextView) reciptViewDynamic.findViewById(R.id.student_profile_fee_amount);
            viewHolder.student_profile_Fee_Description = (TextView) reciptViewDynamic.findViewById(R.id.student_profile_fee_description);
            viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());
            viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());


            viewHolder.receiptLinearLayout.addView(reciptViewDynamic);
            viewHolder.receiptLinearLayout.removeAllViews();


        }


        convertView.setTag(viewHolder);
        return convertView;
    }

    class Holder {
        TextView student_profile_fee_status;
        TextView student_profile_ReceiptIssuedDate;
        TextView student_profile_ReceiptIssuedNumber;
        TextView student_profile_FeeReceivedDate;
        TextView student_profile_Fee_Amount;
        TextView student_profile_Fee_Description;
        LinearLayout receiptLinearLayout;


    }


}

<强>费

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

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


    TextView statustextView, feedescription, feeamount;
    ListView listViewfees, listviewfeedetail;
    List<StudentFeeInformation> yourData = new ArrayList<StudentFeeInformation>();

    public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees";
    String Amount;
    String Descriptionlist, status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate;
    ArrayList arrayList = new ArrayList();
    String master_id;

    LinearLayout linearLayout;
    TextView textView;


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


        View view = inflater.inflate(R.layout.student_fees_listview, container, false);
        inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // view1 = inflater.inflate(R.layout.student_fees_description_data, null);


        setHasOptionsMenu(true);
        receipt1 = (LinearLayout) view.findViewById(R.id.linear_receipt1_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();
        listViewfees = (ListView) view.findViewById(R.id.list_student_fees);
        // listviewfeedetail = (ListView) view.findViewById(R.id.listtest);

        //  DescriptionAmount = (LinearLayout) view.findViewById(R.id.student_profile_fee_linearlayout1);
        // DescriptionAmount.addView(view);


        linearLayout = (LinearLayout) view.findViewById(R.id.student_profile_fee_linearlayout1);
        //   v = (LinearLayout)( view.inflate(getContext(), R.layout.student_fees_description_data, null));
        //  linearLayout.addView(view);

        feedescription = (TextView) view.findViewById(R.id.student_profile_fee_description);
        feeamount = (TextView) view.findViewById(R.id.student_profile_fee_amount);


        textView = (TextView) view.findViewById(R.id.student_profile_fee_amount);


        getUsersListData();


        return view;
    }


    public void getUsersListData() {


        String URL = Navigation_URL + "?id=" + master_id + "&fromDate=" + "&toDate=";
        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<>();
                            ArrayList<ArrayList> student_list_description = new ArrayList<>();


                            JSONArray jArray = new JSONArray(response);

                            //  studentFeeInformation = new StudentFeeInformation(response);
                            for (int i = 0; i < jArray.length(); i++) {
                                JSONObject jsonObject = jArray.getJSONObject(i);

                                status = jsonObject.getString("Status");
                                DateofReceiptIssued = jsonObject.getString("DateOfReciept").substring(0, 10);
                                ReceiptNumber = jsonObject.getString("RecieptNo");
                                FeeReceivedDate = jsonObject.getString("recivedDate").substring(0, 10);


                                String Description = jsonObject.getString("Description");
                                JSONArray jArray1 = new JSONArray(Description);

                                //
                                for (int j = 0; j < jArray1.length(); j++) {


                                    JSONObject jsonObjectinner = jArray1.getJSONObject(j);
                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");
                                    arrayList.add(Descriptionlist);
                                    Log.d("ArrayList", String.valueOf(arrayList));
                                    student_list.add(new StudentFeeInformation(Descriptionlist, Amount));

                                }
                                student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));


                            }

                            System.out.println("student_list size:" + student_list.size());
                            CustomFeeListStudentAdapter customFeeListStudentAdapter = new CustomFeeListStudentAdapter(getActivity(), student_list);

                            listViewfees.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);


    }


    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Auto-generated method stub
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.dashboard, menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // handle item selection
        switch (item.getItemId()) {
            case R.id.action_settings:
                // do s.th.
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

<强> layout_bil_info

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/student_profile_fee_linearlayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/student_profile_fee_description"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left|center"
        android:paddingLeft="70dp"
        android:paddingTop="10dp"
        android:text="Sports"
        android:textSize="10dp" />

    <TextView
        android:id="@+id/student_profile_fee_amount"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left|center"
        android:paddingLeft="70dp"
        android:paddingTop="10dp"
        android:text="1000"
        android:textSize="10dp" />
</LinearLayout>

答案 1 :(得分:0)

试试这个, CustomFeeListStudentAdapter

    //added code
    viewHolder.receiptLinearLayout.removeAllViews();
    for (int i = 0; i < 1; i++) {

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View convertView = layoutinflater.inflate(R.layout.layout_bil_info, null, false);
        convertView.setId(postion);
        TextView student_profile_Fee_Amount = (TextView) convertView.findViewById(R.id.student_profile_fee_amount);
        TextView student_profile_Fee_Description = (TextView) convertView.findViewById(R.id.student_profile_fee_description);
        student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());
        student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());
        viewHolder.receiptLinearLayout.addView(convertView);            
    }