0

It is recommended Everywhere that List Within List shouldnot be used but i have to use same as List Within list.Is there any way that would work same as list within list.I have watched Expandable ListView and this but not able to solve my issue.my requirement Look like

  **ListView**
         **TextView** 
         **TextView** 
         **ListView**(i have used Linear layout in here)

In my Layout i have placed Linear Layout in the Place of inner listView.Inner ListView(Linear Layout in my case) is only setting one JSON Data in the innerView.I want to display that same as outer ListView in Inner.How can this be possible? fragment_fee

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

////this is the replacement of ListView in Inner
                    <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>
  <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>
</LinearLayout>

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>

CustomFeeListStudentAdapter

public class CustomFeeListStudentAdapter extends BaseAdapter {


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


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

        } 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());
        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());


        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;


    }
}

Fee

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

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


    TextView statustextView;
    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;
    String master_id;

    LinearLayout linearLayout;

    //   View view1;

    @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);
        //    linearLayout = (LinearLayout) view1.findViewById(R.id.student_profile_fee_linearlayout1);

        // view1 = inflater.inflate(R.layout.student_fees_description_data, container, false);


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

        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<>();
                            ArrayList<FeeDescriptionStudent> 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");


                                    //  TextView txtQuestion = (TextView) view1.findViewById(R.id.student_profile_fee_description);
                                    //  TextView tx = (TextView) view1.findViewById(R.id.student_profile_fee_amount);


                                    //  System.out.println(txtQuestion);
                                    //  System.out.println(tx);


                                    //  txtQuestion.setText(Descriptionlist);
                                    //  tx.setText(Amount);
                                    // linearLayout.addView(view1);


                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");


                                }

                                student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate, 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);
        }
    }
}

I have watched many example of ExpandableListView as well as TableView but cannot be able to show item as listView.I have used Linear layout in place of ListView but only one JSON data is Displayed.Where is error i am not able to get it.

logcat

03-29 16:52:20.023 1558-1569/system_process I/WindowManager: Destroying surface Surface(name=com.example.user.mis/com.example.user.mis.activity.Login) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService.notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6895 
03-29 16:52:22.656 11984-11984/com.example.user.mis I/System.out: student_list size:3
03-29 16:52:22.656 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.656 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.672 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.672 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.676 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:0 getTeacherNameLate Charge
03-29 16:52:22.677 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:1 getTeacherNameMonthly Fee
03-29 16:52:22.678 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:2 getTeacherNameExtra Charge
03-29 16:52:22.678 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.679 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:0 getTeacherNameLate Charge
03-29 16:52:22.682 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:1 getTeacherNameMonthly Fee
03-29 16:52:22.684 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:2 getTeacherNameExtra Charge
03-29 16:52:23.039 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:23.039 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:23.041 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:0 getTeacherNameLate Charge
03-29 16:52:23.042 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:1 getTeacherNameMonthly Fee
03-29 16:52:23.042 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:2 getTeacherNameExtra Charge
03-29 16:52:23.042 11984-11984/com.example.user.mis I/System.out: 3
Community
  • 1
  • 1
Ghimire
  • 948
  • 1
  • 9
  • 28

2 Answers2

0
  • From that screenshot it seems, there is no point to use listview inside listview. You can use Section header listview or else use just listview and set background color for first item in adapter.

  • In adapter, based on the condition, you can hide and show the child views.

you must add student_list.add inside the for loop like below:

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


      JSONObject jsonObjectinner = jArray1.getJSONObject(j);

      Descriptionlist = jsonObjectinner.getString("des");

      Amount = jsonObjectinner.getString("Amount"); 

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

     }

Layout:

Fees -> You should add this fees title in top of the list view in activity layout not adapter layout.

In Adapter:

First item : Use horizontal linear layout as a first item and set background color green.

Second item : Use horizontal linear layout as a second item and set background color as silver or light transparent color.

Third item : Use horizontal linear layout as a third item.

For all child items : fourth, fifth and sixth items use horizontal linear layout and put two textviews inside that.

Stephen
  • 9,899
  • 16
  • 90
  • 137
  • That is the screenshot i got it man. i want to display as description Amount A 100 B 200 C 300 .....as in list – Ghimire Mar 29 '17 at 10:19
  • Use expandable listview or else follow the layout structure I have mentioned in the answer. – Stephen Mar 29 '17 at 10:55
  • @user2025187 can you please help me. – Ghimire Mar 31 '17 at 05:50
  • @Ghimire yes that also you can do .that is what I mentioned already in this answer.in adapter, use linear layout vertical as a parent. Then below all linearlayout are horizontal – Stephen Mar 31 '17 at 06:20
0

You can use expandable recycler view as explained in Expandable Recycler view

All you need to do is define child for parents 1 and 6. For other positions you can simply treat them as parent with no child.

You need to define proper model class and pass the data in model.

Suresh Basnet
  • 147
  • 2
  • 13
  • How can ExpandableList View be used?As i have Shown in screen Shot 2.The Description Data are to be listed as like the ListView.If i made outer as ExpandableListView then how can all the list Item be added(i.e for inner List) – Ghimire Mar 30 '17 at 10:19
  • @Ghimire all the inner items seems to be child. You can achieve what you want with expandable listview.First try to run sample using expandable list view and understand how they are handling string array.Then parse json to that string array. – Stephen Mar 31 '17 at 06:02
  • @Stephen I am thinking about Can the LinearLayout be inflated with the rowView(in the place of inner list).If yes then my problem will be solved? – Ghimire Mar 31 '17 at 06:04