问:
Unnecessarily view are added in listView
I am using ListView to Display the JSON Data.Within the ListView i have implemented Dynamic LinearLayout to populate as the listitems.I am able to Display the JSON data in the listView as well as within the linearlayout.When the program is exected the view are added unnecessarily.i think the issue is of looping,but dont know exactly.How can this issue be solved?

Fee

```<code>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;
    //  public JSONArray jArray1;

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

                            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);
                                //  student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));
                                //
                                //JSONArray jArray1 = jsonObject.getJSONArray("Description");
                                StudentFeeInformation sInformation = new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate);

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

                                    JSONObject jsonObjectinner = jArray1.getJSONObject(j);
                                    System.out.println("total length" + jArray1.length());
                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");
                                    arrayList.add(Descriptionlist);
                                    Log.d("ArrayList", String.valueOf(arrayList));
                                    //  student_list.add(new StudentFeeInformation(Descriptionlist, Amount));
                                    sInformation.addFeeDescription(Descriptionlist);
                                    sInformation.addAmount(Amount);

                                }

                                System.out.println("total lengthArray" + jArray.length());
                                student_list.add(sInformation);

                            }

                            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);
        }
    }
</code>```

CustomFeeListStudentAdapter

```<code>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());

        // viewHolder.receiptLinearLayout.removeAllViews();
        //added code

        //  Fee fee=new Fee();
        //   JSONArray x=fee.jArray1;

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

        viewHolder.receiptLinearLayout.removeAllViews();
        for (int i = 0; i < student_list.get(postion).getFeeDescription().size(); 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().get(i));
            viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription().get(i));
            System.out.print(viewHolder);

            // Log.d(TAG, "@@ wrong information:" + student_list.get(postion).getFeeDescription());
            viewHolder.receiptLinearLayout.addView(reciptViewDynamic);

            Log.d(TAG, "@@  massive wrong information:" + student_list.get(postion).getFeeDescription().get(i));

        }

        // (reciptViewDynamic).removeView(convertView);
        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;
    }

}
</code>```

json

```<code>[
  {
    "MasterID": "E0017",
    "StdID": 95,
    "Status": "U",
    "AmountPaid": 1200,
    "CLASS_ID": 2021,
    "DateOfReciept": "2017-06-01T00:00:00",
    "Description": "[{\"des\":\"Admission\",\"Amount\":1200},{\"des\":\"Due\",\"Amount\":0}]",
    "dueAmount": 0,
    "receivedAmount": 0,
    "RecieptNo": 80,
    "NAME": "Calvin Patterson",
    "CLASSNO": "1",
    "recivedDate": "2017-06-01T00:00:00",
    "dueDate": "2017-06-29T00:00:00",
    "reciever": "Hari Har Sharma"
  }
]
</code>```

StudentFeeInformation

```<code>public class StudentFeeInformation implements Serializable {
    public String Status;
    public String ReceiptIssuedDate;
    public String ReceiptIssuedNumber;
    public String FeeReceivedDate;
    public String FeeDescription;
    public String Amount;

    public StudentFeeInformation(String status, String ReceiptissuedDate, String ReceiptissuedNumber, String FeereceivedDate) {
        Status = status;
        ReceiptIssuedDate = ReceiptissuedDate;
        ReceiptIssuedNumber = ReceiptissuedNumber;
        FeeReceivedDate = FeereceivedDate;

    }

    public StudentFeeInformation(String feeDescription, String amount) {

        FeeDescription = feeDescription;
        Amount = amount;

    }

    public String getStatus() {
        return Status;
    }

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

    public String getReceiptIssuedDate() {
        return ReceiptIssuedDate;
    }

    public void setReceiptIssuedDate(String receiptIssuedDate) {
        ReceiptIssuedDate = receiptIssuedDate;
    }

    public String getReceiptIssuedNumber() {
        return ReceiptIssuedNumber;
    }

    public void setReceiptIssuedNumber(String receiptIssuedNumber) {
        ReceiptIssuedNumber = receiptIssuedNumber;
    }

    public String getFeeReceivedDate() {
        return FeeReceivedDate;
    }

    public void setFeeReceivedDate(String feeReceivedDate) {
        FeeReceivedDate = feeReceivedDate;
    }

    public String getFeeDescription() {
        return FeeDescription;
    }

    public void setFeeDescription(String feeDescription) {
        FeeDescription = feeDescription;
    }

    public String getAmount() {
        return Amount;
    }

    public void setAmount(String amount) {
        Amount = amount;
    }

}
</code>```

logcat

```<code>   06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: MasterID:0095
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Name:Calvin Patterson
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Access:4
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Issued:Thu, 08 Jun 2017 06:55:22 GMT
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Expires:Fri, 09 Jun 2017 06:55:22 GMT
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: user_name_masterID1:0095
06-08 12:40:21.848 28277-28369/com.example.user.mis E/EGL_emulation: tid 28369: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
06-08 12:40:21.849 28277-28369/com.example.user.mis W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa827f920, error=EGL_BAD_MATCH
06-08 12:40:21.898 28277-28277/com.example.user.mis D/Term ID: 6014
06-08 12:40:21.898 28277-28277/com.example.user.mis D/Term ID: 6015
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6016
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6017
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6018
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6019
06-08 12:40:21.899 28277-28277/com.example.user.mis D/All Exam: 6
06-08 12:40:21.960 28277-28277/com.example.user.mis W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: total length2
06-08 12:40:24.041 28277-28277/com.example.user.mis D/ArrayList: [Admission]
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: total length2
06-08 12:40:24.041 28277-28277/com.example.user.mis D/ArrayList: [Admission, Due]
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: total lengthArray1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: student_list size:1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: response is [{"MasterID":"E0017","StdID":95,"Status":"P","AmountPaid":1200.0,"CLASS_ID":2021,"DateOfReciept":"2017-06-08T00:00:00","Description":"[{\"des\":\"Admission\",\"Amount\":1200},{\"des\":\"Due\",\"Amount\":0}]","dueAmount":1200.0,"receivedAmount":0.0,"RecieptNo":83,"NAME":"Calvin Patterson","CLASSNO":"1","recivedDate":"2017-06-08T00:00:00","dueDate":"2017-06-29T00:00:00","reciever":"Hari Har Sharma"}]
06-08 12:40:24.057 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.057 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.059 28277-28277/com.example.user.mis D/HomeTab_adapter: @@ wrong information:2
06-08 12:40:24.062 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.062 28277-28277/com.example.user.mis D/HomeTab_adapter: @@ wrong information:2
06-08 12:40:24.423 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.423 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.426 28277-28277/com.example.user.mis D/HomeTab_adapter: @@ wrong information:2
06-08 12:40:24.427 28277-28277/com.example.user.mis I/System.out: 1
</code>```

debugged image

 where i am doing wrong i am not able to find out.how can this issue be solved?

答:
Change StudentFeeInformation class according to below.

```<code>public class StudentFeeInformation implements Serializable {
    public String Status;
    public String ReceiptIssuedDate;
    public String ReceiptIssuedNumber;
    public String FeeReceivedDate;

    // take a ArrayList object for description and amount as it can be multiple
    public ArrayList<String> FeeDescription = new ArrayList<String>();
    public ArrayList<String> Amount = new ArrayList<String>();

    public StudentFeeInformation(String status, String ReceiptissuedDate, String ReceiptissuedNumber, String FeereceivedDate) {
        Status = status;
        ReceiptIssuedDate = ReceiptissuedDate;
        ReceiptIssuedNumber = ReceiptissuedNumber;
        FeeReceivedDate = FeereceivedDate;

    }

    public String getStatus() {
        return Status;
    }

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

    public String getReceiptIssuedDate() {
        return ReceiptIssuedDate;
    }

    public void setReceiptIssuedDate(String receiptIssuedDate) {
        ReceiptIssuedDate = receiptIssuedDate;
    }

    public String getReceiptIssuedNumber() {
        return ReceiptIssuedNumber;
    }

    public void setReceiptIssuedNumber(String receiptIssuedNumber) {
        ReceiptIssuedNumber = receiptIssuedNumber;
    }

    public String getFeeReceivedDate() {
        return FeeReceivedDate;
    }

    public void setFeeReceivedDate(String feeReceivedDate) {
        FeeReceivedDate = feeReceivedDate;
    }

    public ArrayList<String> getFeeDescription() {
        return FeeDescription;
    }

    public void setFeeDescription(ArrayList<String> feeDescription) {
        FeeDescription = feeDescription;
    }

    public ArrayList<String> getAmount() {
        return Amount;
    }

    public void setAmount(ArrayList<String> amount) {
        Amount = amount;
    }

    public void addFeeDescription(String description) {
        FeeDescription.add(description);
    }

    public void addAmount(String amount) {
        Amount.add(amount);
    }

}
</code>```

Now, in inner for loop of getUsersListData() method, you are creating new object of StudentFeeInformation and adding in list two times.

```<code>student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));

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

     JSONObject jsonObjectinner = jArray1.getJSONObject(j);
     System.out.println("total length" + jArray1.length());
     Descriptionlist = jsonObjectinner.getString("des");
     Amount = jsonObjectinner.getString("Amount");
     arrayList.add(Descriptionlist);
     Log.d("ArrayList", String.valueOf(arrayList));
     student_list.add(new StudentFeeInformation(Descriptionlist, Amount));
}
</code>```

Change above code as below.

```<code>// create new object of StudentFeeInformation
StudentFeeInformation sInformation = new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));

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

     JSONObject jsonObjectinner = jArray1.getJSONObject(j);
     System.out.println("total length" + jArray1.length());
     Descriptionlist = jsonObjectinner.getString("des");
     Amount = jsonObjectinner.getString("Amount");
     arrayList.add(Descriptionlist);
     Log.d("ArrayList", String.valueOf(arrayList));

     // Add fee Description and amount in same object instead of create new object every time
     sInformation.addFeeDescription(Descriptionlist);
     sInformation.addAmount(Amount)
}
student_list.add(sInformation);
</code>```

Finally, change code inside getView() method of adapter as below.

```<code>    for (int i = 0; i < student_list.get(postion).getFeeDescription().size(); 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().get(i));
        viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription().get(i));

        viewHolder.receiptLinearLayout.addView(reciptViewDynamic);
    }
</code>```

Body:
I am using ListView to Display the JSON Data.Within the ListView i have implemented Dynamic LinearLayout to populate as the listitems.I am able to Display the JSON data in the listView as well as within the linearlayout.When the program is exected the view are added unnecessarily.i think the issue is of looping,but dont know exactly.How can this issue be solved?

Fee

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;
    //  public JSONArray jArray1;

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

                            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);
                                //  student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));
                                //
                                //JSONArray jArray1 = jsonObject.getJSONArray("Description");
                                StudentFeeInformation sInformation = new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate);

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

                                    JSONObject jsonObjectinner = jArray1.getJSONObject(j);
                                    System.out.println("total length" + jArray1.length());
                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");
                                    arrayList.add(Descriptionlist);
                                    Log.d("ArrayList", String.valueOf(arrayList));
                                    //  student_list.add(new StudentFeeInformation(Descriptionlist, Amount));
                                    sInformation.addFeeDescription(Descriptionlist);
                                    sInformation.addAmount(Amount);

                                }

                                System.out.println("total lengthArray" + jArray.length());
                                student_list.add(sInformation);

                            }

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

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

        // viewHolder.receiptLinearLayout.removeAllViews();
        //added code

        //  Fee fee=new Fee();
        //   JSONArray x=fee.jArray1;

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

        viewHolder.receiptLinearLayout.removeAllViews();
        for (int i = 0; i < student_list.get(postion).getFeeDescription().size(); 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().get(i));
            viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription().get(i));
            System.out.print(viewHolder);

            // Log.d(TAG, "@@ wrong information:" + student_list.get(postion).getFeeDescription());
            viewHolder.receiptLinearLayout.addView(reciptViewDynamic);

            Log.d(TAG, "@@  massive wrong information:" + student_list.get(postion).getFeeDescription().get(i));

        }

        // (reciptViewDynamic).removeView(convertView);
        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;
    }

}

json

[
  {
    "MasterID": "E0017",
    "StdID": 95,
    "Status": "U",
    "AmountPaid": 1200,
    "CLASS_ID": 2021,
    "DateOfReciept": "2017-06-01T00:00:00",
    "Description": "[{\"des\":\"Admission\",\"Amount\":1200},{\"des\":\"Due\",\"Amount\":0}]",
    "dueAmount": 0,
    "receivedAmount": 0,
    "RecieptNo": 80,
    "NAME": "Calvin Patterson",
    "CLASSNO": "1",
    "recivedDate": "2017-06-01T00:00:00",
    "dueDate": "2017-06-29T00:00:00",
    "reciever": "Hari Har Sharma"
  }
]

StudentFeeInformation

public class StudentFeeInformation implements Serializable {
    public String Status;
    public String ReceiptIssuedDate;
    public String ReceiptIssuedNumber;
    public String FeeReceivedDate;
    public String FeeDescription;
    public String Amount;

    public StudentFeeInformation(String status, String ReceiptissuedDate, String ReceiptissuedNumber, String FeereceivedDate) {
        Status = status;
        ReceiptIssuedDate = ReceiptissuedDate;
        ReceiptIssuedNumber = ReceiptissuedNumber;
        FeeReceivedDate = FeereceivedDate;

    }

    public StudentFeeInformation(String feeDescription, String amount) {

        FeeDescription = feeDescription;
        Amount = amount;

    }

    public String getStatus() {
        return Status;
    }

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

    public String getReceiptIssuedDate() {
        return ReceiptIssuedDate;
    }

    public void setReceiptIssuedDate(String receiptIssuedDate) {
        ReceiptIssuedDate = receiptIssuedDate;
    }

    public String getReceiptIssuedNumber() {
        return ReceiptIssuedNumber;
    }

    public void setReceiptIssuedNumber(String receiptIssuedNumber) {
        ReceiptIssuedNumber = receiptIssuedNumber;
    }

    public String getFeeReceivedDate() {
        return FeeReceivedDate;
    }

    public void setFeeReceivedDate(String feeReceivedDate) {
        FeeReceivedDate = feeReceivedDate;
    }

    public String getFeeDescription() {
        return FeeDescription;
    }

    public void setFeeDescription(String feeDescription) {
        FeeDescription = feeDescription;
    }

    public String getAmount() {
        return Amount;
    }

    public void setAmount(String amount) {
        Amount = amount;
    }

}

logcat

   06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: MasterID:0095
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Name:Calvin Patterson
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Access:4
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Issued:Thu, 08 Jun 2017 06:55:22 GMT
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: Expires:Fri, 09 Jun 2017 06:55:22 GMT
06-08 12:40:21.519 28277-28277/com.example.user.mis D/TAG: user_name_masterID1:0095
06-08 12:40:21.848 28277-28369/com.example.user.mis E/EGL_emulation: tid 28369: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
06-08 12:40:21.849 28277-28369/com.example.user.mis W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa827f920, error=EGL_BAD_MATCH
06-08 12:40:21.898 28277-28277/com.example.user.mis D/Term ID: 6014
06-08 12:40:21.898 28277-28277/com.example.user.mis D/Term ID: 6015
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6016
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6017
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6018
06-08 12:40:21.899 28277-28277/com.example.user.mis D/Term ID: 6019
06-08 12:40:21.899 28277-28277/com.example.user.mis D/All Exam: 6
06-08 12:40:21.960 28277-28277/com.example.user.mis W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: total length2
06-08 12:40:24.041 28277-28277/com.example.user.mis D/ArrayList: [Admission]
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: total length2
06-08 12:40:24.041 28277-28277/com.example.user.mis D/ArrayList: [Admission, Due]
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: total lengthArray1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: student_list size:1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.041 28277-28277/com.example.user.mis I/System.out: response is [{"MasterID":"E0017","StdID":95,"Status":"P","AmountPaid":1200.0,"CLASS_ID":2021,"DateOfReciept":"2017-06-08T00:00:00","Description":"[{\"des\":\"Admission\",\"Amount\":1200},{\"des\":\"Due\",\"Amount\":0}]","dueAmount":1200.0,"receivedAmount":0.0,"RecieptNo":83,"NAME":"Calvin Patterson","CLASSNO":"1","recivedDate":"2017-06-08T00:00:00","dueDate":"2017-06-29T00:00:00","reciever":"Hari Har Sharma"}]
06-08 12:40:24.057 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.057 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.059 28277-28277/com.example.user.mis D/HomeTab_adapter: @@ wrong information:2
06-08 12:40:24.062 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.062 28277-28277/com.example.user.mis D/HomeTab_adapter: @@ wrong information:2
06-08 12:40:24.423 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.423 28277-28277/com.example.user.mis I/System.out: 1
06-08 12:40:24.426 28277-28277/com.example.user.mis D/HomeTab_adapter: @@ wrong information:2
06-08 12:40:24.427 28277-28277/com.example.user.mis I/System.out: 1

debugged image

 where i am doing wrong i am not able to find out.how can this issue be solved?

Body:
Change StudentFeeInformation class according to below.

public class StudentFeeInformation implements Serializable {
    public String Status;
    public String ReceiptIssuedDate;
    public String ReceiptIssuedNumber;
    public String FeeReceivedDate;

    // take a ArrayList object for description and amount as it can be multiple
    public ArrayList<String> FeeDescription = new ArrayList<String>();
    public ArrayList<String> Amount = new ArrayList<String>();

    public StudentFeeInformation(String status, String ReceiptissuedDate, String ReceiptissuedNumber, String FeereceivedDate) {
        Status = status;
        ReceiptIssuedDate = ReceiptissuedDate;
        ReceiptIssuedNumber = ReceiptissuedNumber;
        FeeReceivedDate = FeereceivedDate;

    }

    public String getStatus() {
        return Status;
    }

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

    public String getReceiptIssuedDate() {
        return ReceiptIssuedDate;
    }

    public void setReceiptIssuedDate(String receiptIssuedDate) {
        ReceiptIssuedDate = receiptIssuedDate;
    }

    public String getReceiptIssuedNumber() {
        return ReceiptIssuedNumber;
    }

    public void setReceiptIssuedNumber(String receiptIssuedNumber) {
        ReceiptIssuedNumber = receiptIssuedNumber;
    }

    public String getFeeReceivedDate() {
        return FeeReceivedDate;
    }

    public void setFeeReceivedDate(String feeReceivedDate) {
        FeeReceivedDate = feeReceivedDate;
    }

    public ArrayList<String> getFeeDescription() {
        return FeeDescription;
    }

    public void setFeeDescription(ArrayList<String> feeDescription) {
        FeeDescription = feeDescription;
    }

    public ArrayList<String> getAmount() {
        return Amount;
    }

    public void setAmount(ArrayList<String> amount) {
        Amount = amount;
    }

    public void addFeeDescription(String description) {
        FeeDescription.add(description);
    }

    public void addAmount(String amount) {
        Amount.add(amount);
    }

}

Now, in inner for loop of getUsersListData() method, you are creating new object of StudentFeeInformation and adding in list two times.

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

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

     JSONObject jsonObjectinner = jArray1.getJSONObject(j);
     System.out.println("total length" + jArray1.length());
     Descriptionlist = jsonObjectinner.getString("des");
     Amount = jsonObjectinner.getString("Amount");
     arrayList.add(Descriptionlist);
     Log.d("ArrayList", String.valueOf(arrayList));
     student_list.add(new StudentFeeInformation(Descriptionlist, Amount));
}

Change above code as below.

// create new object of StudentFeeInformation
StudentFeeInformation sInformation = new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));

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

     JSONObject jsonObjectinner = jArray1.getJSONObject(j);
     System.out.println("total length" + jArray1.length());
     Descriptionlist = jsonObjectinner.getString("des");
     Amount = jsonObjectinner.getString("Amount");
     arrayList.add(Descriptionlist);
     Log.d("ArrayList", String.valueOf(arrayList));

     // Add fee Description and amount in same object instead of create new object every time
     sInformation.addFeeDescription(Descriptionlist);
     sInformation.addAmount(Amount)
}
student_list.add(sInformation);

Finally, change code inside getView() method of adapter as below.

    for (int i = 0; i < student_list.get(postion).getFeeDescription().size(); 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().get(i));
        viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription().get(i));

        viewHolder.receiptLinearLayout.addView(reciptViewDynamic);
    }


来源: stackexchange

问:
Python Tabs Fake or Real
Many tutorial suggest users to use tab with width of 4 while 4 is made using spaces not real tab character. Using real tab also it works so why do people suggest to use spaces of 4 rather than real tab ? I'm a python beginner confused ????

[UPDATE]
Thanks! I am now switching to spaces of 4.

Added following to my .vimrc
"Python

```<code>au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
fu Select_c_style()
    if search('^\t', 'n', 150)
        set shiftwidth=8
        set noexpandtab
    el
        set shiftwidth=4
        set expandtab
    en
endf
</code>```

For other case:

```<code>set noexpandtab                " tabs are tabs, not spaces
</code>```

答: The only reason I can consider may be that if you don't have set up your editor to use tabstop=4 (say, in VIM) your code lines will be longer and it will be inconvenient to read such a code. The only rule should be not to mix tabs and spaces, I think (I have seen code where the single indent was four spaces and the double indent was a tab. It was horrible.)

ContentLicense: CC BY-SA 2.5

Title: Python Tabs Fake or Real

Body:
Many tutorial suggest users to use tab with width of 4 while 4 is made using spaces not real tab character. Using real tab also it works so why do people suggest to use spaces of 4 rather than real tab ? I'm a python beginner confused ????

[UPDATE]
Thanks! I am now switching to spaces of 4.

Added following to my .vimrc
"Python

au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
fu Select_c_style()
    if search('^\t', 'n', 150)
        set shiftwidth=8
        set noexpandtab
    el
        set shiftwidth=4
        set expandtab
    en
endf

For other case:

set noexpandtab                " tabs are tabs, not spaces


问:
How do I upgrade PHP in Mac OS X?
I feel this is an awfully obtuse question to ask, but strangely, this problem is poorly documented.

I would like to upgrade PHP, but there are several problems:

There is no built-in package manager. MacPorts doesn't recognize php as an installed package because it didn't install PHP itself.

Running locate php indicates there are probably many dependencies.

I don't know HOW php was installed, as it was included with the OS, so I don't know whether I should install from source or download binaries. I also don't know the proper way to uninstall the previous version without breaking dependencies.

I am running on Leopard. I have a feeling Apple doesn't want you to upgrade. Would buying Snow Leopard and upgrade solve this problem (and future ones like it)?

答:
Check your current php version in terminal with the following command,

```<code>$ php -v
</code>```

You see current php version in terminal, and next command run in terminal if you want to upgrade your php version with php concat with version liked as,

```<code>$ brew install homebrew/php/php71
</code>```

Please restart terminal if you finished php version upgrade installed and run the command.

```<code>$ php -v
</code>```

Now you see the current php version in terminal....thank

Title: How do I upgrade PHP in Mac OS X?

Body:
Check your current php version in terminal with the following command,

$ php -v

You see current php version in terminal, and next command run in terminal if you want to upgrade your php version with php concat with version liked as,

$ brew install homebrew/php/php71

Please restart terminal if you finished php version upgrade installed and run the command.

$ php -v

Now you see the current php version in terminal....thank

ContentLicense: CC BY-SA 3.0


问:
AttributeError: 'list' object has no attribute 'readlines' (Python 3.4.4)
I am currently trying to read a text file and then print it into the Python Shell. It reads the file perfectly fine, but when it goes the read the lines seperately it tells me there is a AttributeError. How could I fix this?

Here's my code:

```<code>import time
import linecache
print("Welcome to the League Fixture Manager!")
time.sleep(3)
print("What would you like to do?")
time.sleep(1)
print("Press A to search for a fixture.")
time.sleep(0.1)
print("Press B to view Outstanding fixtures.")
time.sleep(0.1)
print("Press C to display the leader board")
time.sleep(0.1)
print("Or press Q to quit, this will exit the application.")
time.sleep(0.1)
menuOptions = input("What would you like to do? A, B, C, or Q.")
if menuOptions == 'A':
    print("Searching for fixtures...")
    time.sleep(3)
    data = [line.strip() for line in open("Y:/Computing & Business/Students/Computing/Year 10/CA 2017 Edexcel/firesideFixtures.txt").readlines()]
    lines = data.readlines()
    print(data)
    time.sleep(1)
    print("Return to menu?")
    menuReturn = input("Y or N")
    if menuReturn == 'Y':
        print("Press B to view outstanding fixtures.")
        time.sleep(0.1)
        print("Press C to display the leaderboard")
        time.sleep(0.1)
        print("Or press Q to exit the application.")
        time.sleep(0.1)
        print("You cannot review the fixture list now you have seen it however you can scroll up to view it again.")
        time.sleep(0.1)
        menuOptions2 = input("What would you like to do? B, C, or Q?")
        if menuOptions2 == 'B':
            print("~~incomplete~~")
        elif menuOptions2 == 'C':
            print("~~incomplete~~")
        elif menuOptions2 == 'Q':
            print("Exiting Application...")
            time.sleep(1)
            exit()
    elif menuReturn == 'N':
        print("Exiting Application...")
        time.sleep(2)
        exit()
elif menuOptions == 'B':
    print("~~incomplete~~")
elif menuOptions == 'C':
    print("~~incomplete~~")
elif menuOptions == 'Q':
    print("Exiting Applicaion...")
    time.sleep(2)
    exit()
</code>```

And this is what I recieve:

```<code>Welcome to the League Fixture Manager!
What would you like to do?
Press A to search for a fixture.
Press B to view Outstanding fixtures.
Press C to display the leader board
Or press Q to quit, this will exit the application.
What would you like to do? A, B, C, or Q.A
Searching for fixtures...
Traceback (most recent call last):
  File "E:\Python\Python Work\League\League3.py", line 20, in <module>
    lines = data.readlines()
AttributeError: 'list' object has no attribute 'readlines'
</code>```

答:
You're trying to apply readlines to a list. In your example, data is already a list which contains the file lines. The line:

```<code>lines = data.readlines()
</code>```

is redundant. You can remove it. More, bear with the fact that the method readlines() reads until EOF using readline() and already returns a list containing the lines.

More, I recommend using with() when you work with files:

```<code>with open(some_file) as f:
    ....
</code>```

The advantage of using a with statement is that it is guaranteed to close the file (thing that you didn't do) no matter how the nested block exits. If an exception occurs before the end of the block, it will close the file before the exception is caught by an outer exception handler.

As per your printing request, just loop over the list and print it out:

```<code>for line in data:
    print(line)
</code>```

I recommend you read the official Python documentation.

About files

About lists

About for loop

Body:
I am currently trying to read a text file and then print it into the Python Shell. It reads the file perfectly fine, but when it goes the read the lines seperately it tells me there is a AttributeError. How could I fix this?

Here's my code:

import time
import linecache
print("Welcome to the League Fixture Manager!")
time.sleep(3)
print("What would you like to do?")
time.sleep(1)
print("Press A to search for a fixture.")
time.sleep(0.1)
print("Press B to view Outstanding fixtures.")
time.sleep(0.1)
print("Press C to display the leader board")
time.sleep(0.1)
print("Or press Q to quit, this will exit the application.")
time.sleep(0.1)
menuOptions = input("What would you like to do? A, B, C, or Q.")
if menuOptions == 'A':
    print("Searching for fixtures...")
    time.sleep(3)
    data = [line.strip() for line in open("Y:/Computing & Business/Students/Computing/Year 10/CA 2017 Edexcel/firesideFixtures.txt").readlines()]
    lines = data.readlines()
    print(data)
    time.sleep(1)
    print("Return to menu?")
    menuReturn = input("Y or N")
    if menuReturn == 'Y':
        print("Press B to view outstanding fixtures.")
        time.sleep(0.1)
        print("Press C to display the leaderboard")
        time.sleep(0.1)
        print("Or press Q to exit the application.")
        time.sleep(0.1)
        print("You cannot review the fixture list now you have seen it however you can scroll up to view it again.")
        time.sleep(0.1)
        menuOptions2 = input("What would you like to do? B, C, or Q?")
        if menuOptions2 == 'B':
            print("~~incomplete~~")
        elif menuOptions2 == 'C':
            print("~~incomplete~~")
        elif menuOptions2 == 'Q':
            print("Exiting Application...")
            time.sleep(1)
            exit()
    elif menuReturn == 'N':
        print("Exiting Application...")
        time.sleep(2)
        exit()
elif menuOptions == 'B':
    print("~~incomplete~~")
elif menuOptions == 'C':
    print("~~incomplete~~")
elif menuOptions == 'Q':
    print("Exiting Applicaion...")
    time.sleep(2)
    exit()

And this is what I recieve:

Welcome to the League Fixture Manager!
What would you like to do?
Press A to search for a fixture.
Press B to view Outstanding fixtures.
Press C to display the leader board
Or press Q to quit, this will exit the application.
What would you like to do? A, B, C, or Q.A
Searching for fixtures...
Traceback (most recent call last):
  File "E:\Python\Python Work\League\League3.py", line 20, in <module>
    lines = data.readlines()
AttributeError: 'list' object has no attribute 'readlines'

Body:
You're trying to apply readlines to a list. In your example, data is already a list which contains the file lines. The line:

lines = data.readlines()

is redundant. You can remove it. More, bear with the fact that the method readlines() reads until EOF using readline() and already returns a list containing the lines.

More, I recommend using with() when you work with files:

with open(some_file) as f:
    ....

The advantage of using a with statement is that it is guaranteed to close the file (thing that you didn't do) no matter how the nested block exits. If an exception occurs before the end of the block, it will close the file before the exception is caught by an outer exception handler.

As per your printing request, just loop over the list and print it out:

for line in data:
    print(line)

I recommend you read the official Python documentation.

About files

About lists

About for loop


问:
Uncaught Type error in Google console
While creating a basic google map I AM getting the following error: Uncaught typeError: Cannot read property 'maps' of undefined

Index.html file is:

```<code>    <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">

</head>
<body>
<div id="map-canvas"></div>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBKNPX_2z_JDWcyADlzzFk9JChR4TwhZLQ"
    async defer></script>
    </script>
<script src="script.js"></script>
</body>

</html>
</code>```

the script .js file is:

```<code>    (function(window,google)
{
//maps options
var options={
    center: {
    lat:"0",
    lng:"0"
},
zoom:0
},
//maps
element=document.getElementById('map-canvas'),
map = new google.maps.Map(element,options);
}(window,window.google));
</code>```

The css file is:

```<code>html {
    height: 100%;
}
body {
    height:100%;
    padding: 0;
    margin: 0;
}
#map-canvas {
    height: 100%;
}
</code>```

答:
The error is telling you the Google Maps Javascript API v3 is not loaded when you are trying to run code that depends on it.

You are loading the Google Maps Javascript API v3 using "async defer", but loading your script inline, you need to either defer both or load both without the "async defer".

Title: Uncaught Type error in Google console

Body:
While creating a basic google map I AM getting the following error: Uncaught typeError: Cannot read property 'maps' of undefined

Index.html file is:

    <!DOCTYPE html>

<link rel="stylesheet" href="style.css">

    </script>

the script .js file is:

    (function(window,google)
{
//maps options
var options={
    center: {
    lat:"0",
    lng:"0"
},
zoom:0
},
//maps
element=document.getElementById('map-canvas'),
map = new google.maps.Map(element,options);
}(window,window.google));

The css file is:

html {
    height: 100%;
}
body {
    height:100%;
    padding: 0;
    margin: 0;
}
#map-canvas {
    height: 100%;
}


问:
Polymer element not displaying
I am working on a Polymer website and am having some issues. I previously had my main logic in index.html, and I just moved all of the logic from it into a web component I created called app.html. The website worked fine when everything was in index.html, but when I put it all into the web component and created the element in index.html instead, the page is now blank. There are no script errors or anything.

index.html:

```<code><!doctype html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

  <!-- Add to homescreen for Chrome on Android -->
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="PSK">
  <link rel="icon" sizes="192x192" href="images/touch/chrome-touch-icon-192x192.png">

  <!-- build:css styles/main.css -->
  <link rel="stylesheet" href="styles/main.css">
  <!-- endbuild-->

  <!-- build:js bower_components/webcomponentsjs/webcomponents-lite.min.js -->
  <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <!-- endbuild -->

  <link rel="import" href="elements/app.html">

  <!-- For shared styles, shared-styles.html import in elements.html -->
  <style is="custom-style" include="shared-styles"></style>
</head>

<body fullbleed unresolved>
  <joyce-app></joyce-app>

  <!-- build:js scripts/app.js -->
  <script src="scripts/app.js"></script>
  <!-- endbuild-->
</body>

</html>
</code>```

app.html:

```<code><link rel="import" href="../bower_components/polymer/polymer.html">
<!-- Iron elements -->
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/iron-icons/communication-icons.html">
<link rel="import" href="custom-icons.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/iron-image/iron-image.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">

<!-- Paper elements -->
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-card/paper-card.html">
<link rel="import" href="../bower_components/paper-fab/paper-fab.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-input/paper-textarea.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
<link rel="import" href="../bower_components/paper-material/paper-material.html">
<link rel="import" href="../bower_components/paper-scroll-header-panel/paper-scroll-header-panel.html">
<link rel="import" href="../bower_components/paper-styles/paper-styles-classes.html">
<link rel="import" href="../bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../bower_components/paper-toolbar/paper-toolbar.html">

<!-- Neon elements -->
<link rel="import" href="../bower_components/neon-animation/neon-animated-pages.html">
<link rel="import" href="../bower_components/neon-animation/neon-animatable.html">
<link rel="import" href="../bower_components/neon-animation/neon-animations.html">

<link rel="import" href="../bower_components/firebase-element/firebase-auth.html">

<!-- Routing -->
<link rel="import" href="../bower_components/app-router/app-router.html">

<!-- My elements -->
<link rel="import" href="../styles/app-theme.html">
<link rel="import" href="../styles/shared-styles.html">
<link rel="import" href="blog.html">
<link rel="import" href="artist.html">
<link rel="import" href="teacher.html">
<link rel="import" href="research.html">
<link rel="import" href="contact.html">
<link rel="import" href="login.html">
<link rel="import" href="simple-overlay.html">

<dom-module id="joyce-app">
  <template>
    <!-- Main Area -->
    <paper-scroll-header-panel main condenses keep-condensed-header>
      <!-- Main Toolbar -->
      <paper-toolbar id="mainToolbar" class="medium-tall">

      <div class="center horizontal layout fit">
          <div class="app-name">My Website</div>
          <span class="flex"></span>
          <paper-icon-button icon="account-circle" onclick="login.open()" hidden?="{{!statusKnown || user}}"></paper-icon-button>
          <paper-icon-button icon="account-square" onclick="{{logout}}" hidden?="{{!statusKnown || !user}}"></paper-icon-button>
          <template if="{{user}}">{{user.password.username}}</template>
        </div>

        <!-- Application sub title -->
        <div class="bottom bottom-container center layout flex fit">
          <div class="bottom-title paper-font-subhead">
            <paper-tabs id="nav" selected="{{selected}}">
                  <paper-tab><a href="#/"><iron-icon icon="home"></iron-icon></a></paper-tab>
                  <paper-tab><a href="#/artist"><iron-icon icon="custom-icons:brush"></iron-icon></a></paper-tab>
                  <paper-tab><a href="#/teacher"><iron-icon icon="custom-icons:apple"></iron-icon></a></paper-tab>
                  <paper-tab><a href="#/research"><iron-icon icon="custom-icons:book"></iron-icon></a></paper-tab>
                  <paper-tab><a href="#/contact"><iron-icon icon="mail"></iron-icon></a></paper-tab>
            </paper-tabs>
          </div>
        </div>
      </paper-toolbar>

      <!-- Main Content -->
      <div class="content">
        <app-router style="display:none;">
          <app-route path="/" import="/elements/blog.html"></app-route>
          <app-route path="/artist" import="/elements/artist.html"></app-route>
          <app-route path="/teacher" import="/elements/teacher.html"></app-route>
          <app-route path="/research" import="/elements/research.html"></app-route>
          <app-route path="/contact" import="/elements/contact.html"></app-route>
          <app-route path="*" import="/elements/blog.html"></app-route>
        </app-router>
        <neon-animated-pages style="height:100%" id="pages" class="flex" selected="{{selected}}" entry-animation="scale-up-animation" exit-animation="fade-out-animation">
          <neon-animatable><joyce-blog></joyce-blog></neon-animatable>
          <neon-animatable><joyce-artist></joyce-artist></neon-animatable>
          <neon-animatable><joyce-teacher></joyce-teacher></neon-animatable>
          <neon-animatable><joyce-research></joyce-research></neon-animatable>
          <neon-animatable><joyce-contact></joyce-contact></neon-animatable>
        </neon-animated-pages>
      </div>

      <simple-overlay id="login" with-backdrop>
        <joyce-login></joyce-login>
      </simple-overlay>
    </paper-scroll-header-panel>
  </template>
  <script>
    (function () {
      'use strict';

      Polymer({
        is: 'joyce-app',

        login: function() {
          var params = {};
          params.email = this.email;
          params.password = this.password;
          this.$.firebaseLogin.login(params);
        },
        create: function() {
          this.$.firebaseLogin.createUser(this.email, this.password);
        },
        errorHandler: function(e) {
          this.message = 'Error: ' + e.detail.message;
        }
      });
    })();
  </script>
</dom-module>
</code>```

I have been struggling with this for a week and absolutely cannot figure out what I'm doing wrong. I am able to reference other elements instead of joyce-app

答:
Don't forget to add this to your index.html if you're having a reference error(polymer not defined)</p>

```<code><link rel="import" href="/bower_components/polymer/polymer.html">
</code>```

Title: Polymer element not displaying

Body:
I am working on a Polymer website and am having some issues. I previously had my main logic in index.html, and I just moved all of the logic from it into a web component I created called app.html. The website worked fine when everything was in index.html, but when I put it all into the web component and created the element in index.html instead, the page is now blank. There are no script errors or anything.

index.html:

<!doctype html>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="PSK">
  <link rel="icon" sizes="192x192" href="images/touch/chrome-touch-icon-192x192.png">

  <link rel="stylesheet" href="styles/main.css">

  <link rel="import" href="elements/app.html">

  <joyce-app></joyce-app>

app.html:

<link rel="import" href="../bower_components/polymer/polymer.html">

<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/iron-icons/communication-icons.html">
<link rel="import" href="custom-icons.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/iron-image/iron-image.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">

<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-card/paper-card.html">
<link rel="import" href="../bower_components/paper-fab/paper-fab.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-input/paper-textarea.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
<link rel="import" href="../bower_components/paper-material/paper-material.html">
<link rel="import" href="../bower_components/paper-scroll-header-panel/paper-scroll-header-panel.html">
<link rel="import" href="../bower_components/paper-styles/paper-styles-classes.html">
<link rel="import" href="../bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../bower_components/paper-toolbar/paper-toolbar.html">

<link rel="import" href="../bower_components/neon-animation/neon-animated-pages.html">
<link rel="import" href="../bower_components/neon-animation/neon-animatable.html">
<link rel="import" href="../bower_components/neon-animation/neon-animations.html">

<link rel="import" href="../bower_components/firebase-element/firebase-auth.html">

<link rel="import" href="../bower_components/app-router/app-router.html">

<link rel="import" href="../styles/app-theme.html">
<link rel="import" href="../styles/shared-styles.html">
<link rel="import" href="blog.html">
<link rel="import" href="artist.html">
<link rel="import" href="teacher.html">
<link rel="import" href="research.html">
<link rel="import" href="contact.html">
<link rel="import" href="login.html">
<link rel="import" href="simple-overlay.html">

<dom-module id="joyce-app">
  <template>

    <paper-scroll-header-panel main condenses keep-condensed-header>

      <paper-toolbar id="mainToolbar" class="medium-tall">

My Website

          <paper-icon-button icon="account-circle" onclick="login.open()" hidden?="{{!statusKnown || user}}"></paper-icon-button>
          <paper-icon-button icon="account-square" onclick="{{logout}}" hidden?="{{!statusKnown || !user}}"></paper-icon-button>
          <template if="{{user}}">{{user.password.username}}</template>

            <paper-tabs id="nav" selected="{{selected}}">
                  <paper-tab><iron-icon icon="home"></iron-icon></paper-tab>
                  <paper-tab><iron-icon icon="custom-icons:brush"></iron-icon></paper-tab>
                  <paper-tab><iron-icon icon="custom-icons:apple"></iron-icon></paper-tab>
                  <paper-tab><iron-icon icon="custom-icons:book"></iron-icon></paper-tab>
                  <paper-tab><iron-icon icon="mail"></iron-icon></paper-tab>
            </paper-tabs>

      </paper-toolbar>

        <app-router style="display:none;">
          <app-route path="/" import="/elements/blog.html"></app-route>
          <app-route path="/artist" import="/elements/artist.html"></app-route>
          <app-route path="/teacher" import="/elements/teacher.html"></app-route>
          <app-route path="/research" import="/elements/research.html"></app-route>
          <app-route path="/contact" import="/elements/contact.html"></app-route>
          <app-route path="*" import="/elements/blog.html"></app-route>
        </app-router>
        <neon-animated-pages style="height:100%" id="pages" class="flex" selected="{{selected}}" entry-animation="scale-up-animation" exit-animation="fade-out-animation">
          <neon-animatable><joyce-blog></joyce-blog></neon-animatable>
          <neon-animatable><joyce-artist></joyce-artist></neon-animatable>
          <neon-animatable><joyce-teacher></joyce-teacher></neon-animatable>
          <neon-animatable><joyce-research></joyce-research></neon-animatable>
          <neon-animatable><joyce-contact></joyce-contact></neon-animatable>
        </neon-animated-pages>

      <simple-overlay id="login" with-backdrop>
        <joyce-login></joyce-login>
      </simple-overlay>
    </paper-scroll-header-panel>
  </template>

</dom-module>

I have been struggling with this for a week and absolutely cannot figure out what I'm doing wrong. I am able to reference other elements instead of joyce-app

Body:
Don't forget to add this to your index.html if you're having a reference error(polymer not defined)

<link rel="import" href="/bower_components/polymer/polymer.html">


问:
Add content after text
Is it possible to add text by pseudo-selector ::after or ::before to a specyfic word?
For ex. I would like to add pdf icon always next to word "Download".
[PDF] Download

Or maybe is it another method?

答:
your link on pdf need contain pdf, then you could use this selector:

a[href*="pdf"]:before {content: '[ICON] '}
a[href*="pdf"]:after {content: ' ';}```
<pre class="snippet-code-html lang-html prettyprint-override"><code>learn html and css in one week</code>```

Title: Add content after text

Body:
your link on pdf need contain pdf, then you could use this selector:

a[href*="pdf"]:before {content: '[ICON] '}
a[href*="pdf"]:after {content: ' ';}

<a href="http://example.com/test.pdf" class="pdf">learn html and css in one week</a>


问:
why GUID uniqueidentifier show value slightly different
We have an user table which the userId is an uniqueidentifier type in Sybase database. The value we put in is a GUID value from our C# application. When we look at the table via Sybase tool, the value shows as 3835FD60-ACDE-4345-99AB-54263E9A07AE. When we copy/paste that field to a text file, it shows as 0x3835fd60acde434599ab54263e9a07ae. When we access that field using  odbc (in python) generates the (Hex) string as
3835FD60ACDE434599AB54263E9A07AE.

Why it shows differently?
thanks

答:
A Guid is just a set of bytes; it isn't a string. The same as an integer 123 isn't the string "123". There are various ways of displaying it as a human readable string. You can use the format specifier with Guid.ToString(string) to choose a format: http://msdn.microsoft.com/en-us/library/97af8hh4.aspx

Simply: they chose to use different formats. The Guid is the same.


问:
Extracting sub arrays from a two dimensional array for each element and displaying them in a table using KnockoutJS
I have used below code in PHP to extract data from MySQL :

```<code><?php
require("connect.php");
$sql = "SELECT `inn_lay_list`, `inner_layer` FROM `da_customer_auto_inner`
where `mpcode` = 'qf017'";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)) {
    $data1 = $row['inn_lay_list'];
    $data2 = $row['inner_layer'];
}

$parts1 = explode(';',$data1);
$parts2 = explode(';',$data2);
$layer_cnt = count($parts1);
$array_inner = array_chunk($parts2, 8);

echo json_encode($parts1);
echo json_encode($array_inner);

mysqli_close($conn);
?>
</code>```

I obtained the result as:

["001","011","021","031"]

[["1","2","3","4","5","6","7","8"], ["11","12","13","14","15","16","17","18"], ["21","22","23","24","25","26","27","28"],[31","32","33","34","35","36","37","38"]]

Here for each element in first array there is a sub array in the second array(two dimensional array).
Now I want to display this in HTML page using a table. I am trying to use KnockoutJS “foreach” option with a named template:

```<code><script>
function MyViewModel() {
    this.layer = [{
        name: "<?=@$parts1[0]?>",
        layer_data: "<?=@$array_inner[0]?>"
    },
    {
        name: "<?=@$parts1[1]?>",
        layer_data: "<?=@$array_inner[1]?>"
    },
    {
        name: "<?=@$parts1[2]?>",
        layer_data: "<?=@$array_inner[2]?>"
    },
    {
        name: "<?=@$parts1[3]?>",
        layer_data: "<?=@$array_inner[3]?>"
    }]
}
ko.applyBindings(new MyViewModel());
</script>

<table class="table table-bordered">
    <thead>
    <tr>
      <td>Layer</td>
      <td>P2P</td>
      <td>P2T</td>
      <td>T2T</td>
      <td>Track Width</td>
      <td>PTH To Cu</td>
      <td>NPTH To Cu</td>
      <td>PTH AR</td>
      <td>Via AR</td>
    </tr>
    </thead>
    <tbody data-bind="template:{name:'layer-template', foreach:layer}">
    </tbody>
</table>
<script type="text/html" id="layer-template">
<tr>
    <td data-bind="text: name"></td>
    <td data-bind="text: layer_data[0]"></td>
    <td data-bind="text: layer_data[1]"></td>
    <td data-bind="text: layer_data[2]"></td>
    <td data-bind="text: layer_data[3]"></td>
    <td data-bind="text: layer_data[4]"></td>
    <td data-bind="text: layer_data[5]"></td>
    <td data-bind="text: layer_data[6]"></td>
    <td data-bind="text: layer_data[7]"></td>
</tr>
</script>
</code>```

I want my output as below :

答:
use current() function returns the value of the current element in an array.

```<code><?php

$array=[[1,2,3], [4,5,6], [7,8,9]];

var_dump(current($array));

?>
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have used below code in PHP to extract data from MySQL :

<?php
require("connect.php");
$sql = "SELECT `inn_lay_list`, `inner_layer` FROM `da_customer_auto_inner`
where `mpcode` = 'qf017'";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)) {
    $data1 = $row['inn_lay_list'];
    $data2 = $row['inner_layer'];
}

$parts1 = explode(';',$data1);
$parts2 = explode(';',$data2);
$layer_cnt = count($parts1);
$array_inner = array_chunk($parts2, 8);

echo json_encode($parts1);
echo json_encode($array_inner);

mysqli_close($conn);
?>

I obtained the result as:

["001","011","021","031"]

[["1","2","3","4","5","6","7","8"], ["11","12","13","14","15","16","17","18"], ["21","22","23","24","25","26","27","28"],[31","32","33","34","35","36","37","38"]]

Here for each element in first array there is a sub array in the second array(two dimensional array).
Now I want to display this in HTML page using a table. I am trying to use KnockoutJS “foreach” option with a named template:

      Layer
      P2P
      P2T
      T2T
      Track Width
      PTH To Cu
      NPTH To Cu
      PTH AR
      Via AR

I want my output as below :

Body:
use current() function returns the value of the current element in an array.

<?php

$array=[[1,2,3], [4,5,6], [7,8,9]];

var_dump(current($array));

?>


问:
Appending NSString with Zeros depending upon length
I have a string, length may vary but I have to check if its length is less then 12 and if yes append those many zeros to it.

Like:

str = Test123, output should be Test12300000

str = Test123456, output should be Test12345600

Only 12 Char is allowed in string.

Tried below code but not getting generic result. There must be a better and easy way to do.

```<code>- (NSString *)formatValue:(NSString *)str forDigits:(NSString *)zeros {
    return [NSString stringWithFormat:@"%@%@", str ,zeros];
}
</code>```

答:
This is fast and simple, I think.

```<code>- (NSString *)stringToFormat:(NSString *)str {
    return [str stringByAppendingString:[@"000000000000" substringFromIndex:str.length]];
}
</code>```

Just make sure the string is never more than 12 characters.

Body:
I have a string, length may vary but I have to check if its length is less then 12 and if yes append those many zeros to it.

Like:

str = Test123, output should be Test12300000

str = Test123456, output should be Test12345600

Only 12 Char is allowed in string.

Tried below code but not getting generic result. There must be a better and easy way to do.

- (NSString *)formatValue:(NSString *)str forDigits:(NSString *)zeros {
    return [NSString stringWithFormat:@"%@%@", str ,zeros];
}

Body:
This is fast and simple, I think.

- (NSString *)stringToFormat:(NSString *)str {
    return [str stringByAppendingString:[@"000000000000" substringFromIndex:str.length]];
}

Just make sure the string is never more than 12 characters.


问:
Easiest way to validate and read an xml file in .net?
What is the easiest/simplest/cleanest way to:

Read an xml file from the filesystem

Validate the xml against an xsd

Read parts of the xml file into variables

Using .net.

答:
Use the XMLDocument and XMLNode objects.

You can use the Load and LoadXML methods in XMLDocument to load a xml document. Then you can use the SelectSingleNode to get a value based on the XPath of that node.  Or you can use the SelectNodes method to load in an entire node.

You can use the Validate method of the XMLDocument object to validate the XML up against a XSD.

OwnerDisplayName: webdtc

OwnerDisplayName: Loukas

LastEditorDisplayName: Loukas


答:
The problem is the POSIXlt index. You should convert it to POSIXct, which is most easily accomplished by creating a new xts object. Try the commands below.

```<code>e <- xts(coredata(e), as.POSIXct(index(e)))
PerformanceAnalytics::charts.PerformanceSummary(e[,1:10])
</code>```

The chart throws an error with your example data, after drawing the first plot:

```<code>Error in segments(xlim[1], y_grid_lines(ylim), xlim[2], y_grid_lines(ylim),  :
  cannot mix zero-length and non-zero-length coordinates
</code>```

But that may be because there aren't enough observations. Let me know if it doesn't work on your actual data and I'll investigate further.

Title: charts.PerformanceSummary() not working for intraday data

Body:
I am trying to plot intraday data using PerformanceAnalytics::charts.PerformanceSummary()

but I get the following error message:

charts.PerformanceSummary(e[,1:10])

Error in as.POSIXlt.POSIXct(.POSIXct(.index(x)), tz = indexTZ(x)) :
      invalid 'tz' value

It seems that charts.PerformanceSummary only takes daily data but not intraday?

Can someone please come up with a solution for this?

 e <- structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0.000369303493611195, 0,
0, 0.000590667454223315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000150829562594268,
0.000150806816467952, -0.00015078407720126, -0.000150806816468174,
0.000301659125188536, 0, 0, -0.000617817867292869, 0, 0, 0, 0,
0.000107944732297138, 0.000323799244468459, -0.000215796288303927,
0, 0.000215842866393423, 0, 0, 0, 0, 0, 0), class = c("xts",
"zoo"), .indexCLASS = c("POSIXlt", "POSIXt"), tclass = c("POSIXlt",
"POSIXt"), .indexTZ = c("America/New_York", "EST", "EDT"), tzone = c("America/New_York",
"EST", "EDT"), index = structure(c(1496755860, 1496755920, 1496755980,
1496756040, 1496756100, 1496756160), tzone = c("America/New_York",
"EST", "EDT"), tclass = c("POSIXlt", "POSIXt")), .Dim = c(6L,
10L), .Dimnames = list(NULL, c("AADR", "AAXJ", "ACIM", "ACSI",
"ACTX", "ACWF", "ACWI", "ACWV", "ACWX", "ADRA")))

Body:
The problem is the POSIXlt index. You should convert it to POSIXct, which is most easily accomplished by creating a new xts object. Try the commands below.

e <- xts(coredata(e), as.POSIXct(index(e)))
PerformanceAnalytics::charts.PerformanceSummary(e[,1:10])

The chart throws an error with your example data, after drawing the first plot:

Error in segments(xlim[1], y_grid_lines(ylim), xlim[2], y_grid_lines(ylim),  :
  cannot mix zero-length and non-zero-length coordinates

But that may be because there aren't enough observations. Let me know if it doesn't work on your actual data and I'll investigate further.


问:
How can I select this elements using selenium webdriver
```<code><div class="table-row ng-scope" ng-repeat="territory in allTerritories | filter:query">

<div class="table-row ng-scope" ng-repeat="territory in allTerritories | filter:{selected:true}">
</code>```

<p>Does any know how to select above elements using webdriver. The only difference of them is the filter attribute. </p>

答:
You can use cssSelector to select by attribute partial content

```<code>driver.findElement(By.cssSelector(".table-row[ng-repeat*='query']"));

driver.findElement(By.cssSelector(".table-row[ng-repeat*='selected']"));
</code>```

Body:
You can use cssSelector to select by attribute partial content

driver.findElement(By.cssSelector(".table-row[ng-repeat*='query']"));

driver.findElement(By.cssSelector(".table-row[ng-repeat*='selected']"));


问:
Magento 2: Send Email REST API
How can I build REST API for sending email?

As example build it as :

```<code>/V1/email/send/?username=aaa@example.com&message=text
</code>```

答:
Magento2 can not send custom emails in API.
But the basic interface will have an e-mail notification

E.g

```<code>  API:POST /V1/order/{orderId}/ship
</code>```

the parameter can be set

```<code>{
...
"notify": true,
...
}
</code>```

Title: Magento 2: Send Email REST API

Body:
How can I build REST API for sending email?

As example build it as :

/V1/email/send/?username=aaa@example.com&message=text

Body:
Magento2 can not send custom emails in API.
But the basic interface will have an e-mail notification

E.g

  API:POST /V1/order/{orderId}/ship

the parameter can be set

{
...
"notify": true,
...
}


问:
Which thread does Dialog.show() run on?
Does Dialog.show() method run on the UI thread or does it run on another thread? </p>

答: Dialog is a UI component of Android. All UI components run on the UI thread. If you run it from a background thread, you need to have a looper so that dialog.show can work.</p>

Title: Which thread does Dialog.show() run on?


问:
phpMyAdmin database backup download stops at 5.6MB
Everytime when I download my database by exporting to SQL gzipped file, it stops at 5.6MB. Previously it was ok to download the entire copy of 26MB. What should I do?

Thanks.

答:
if you are on linux even though it sounds nasty try

wget (URL HERE) (directory here)

also check to make sure you have enough room on your computer, try a different browser


问:
SQL Server design
I am trying to build a c# application with visual studio. One of my design problems is this:

A costumer creates a request(For some service), which will be stored on a "Requests Table" in the database.

Every company can make a "bid", where it will give the service for price X.

The student will then look at each request and choose the one which suits him best.

Thus, every "bid" needs to keep the Company name, and the bid price.

How can i store the "bids" on an SQL server?
I thought of creating a Table for each request which stores the bids, but it seems to take a lot of space.

Thanks!

答:
You don't need a table for each request. You should be done with these tables:

Customers: CustomerId

Services: ServiceId

Requests: CustomerId, ServiceId

Companies: CompanyId

Bids: CompanyId, RequestId

Title: SQL Server design


答:
You can use of :after or :before for insert content to Elements no text. my suggestion is wrap text in span with class and use :after or :before.

.pdf:after {
  content: ' Download';
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><span class="pdf">[PDF]</span></code>```

For a Elements use a[href$=".pdf"]

a[href$=".pdf"]:after {
  content: ' Download'
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code>Book</code>```

Title: Add content after text

Body:
Is it possible to add text by pseudo-selector ::after or ::before to a specyfic word?
For ex. I would like to add pdf icon always next to word "Download".
[PDF] Download

Or maybe is it another method?

Body:
You can use of :after or :before for insert content to Elements no text. my suggestion is wrap text in span with class and use :after or :before.

.pdf:after {
  content: ' Download';
}

<span class="pdf">[PDF]</span>

For a Elements use a[href$=".pdf"]

a[href$=".pdf"]:after {
  content: ' Download'
}

<a href="http://e-book.com/css.pdf" class="pdf">Book</a>


问:
Return multiple strings from dll
we are having a discussion as what is a good way to return multiple strings from one dll function. Currently we have 8 strings, but there will be more. For simplicity I now consider all strings will have equal lengths.

```<code>extern "C" int DLLNAME_ _stdcall GetResult(TestResults* testResults);
</code>```

where

```<code>struct TestResults
{
    int stringLengths;
    char* string1;
    char* string2;
    char* string3;
    char* string4;
    ...
};
</code>```

or second option: where

```<code>struct TestResults
{
    int stringLengths;
    char string1[64];
    char string2[64];
    char string3[64];
    char string4[64];
    ...
};
</code>```

third option:
extern "C" int DLLNAME_ _stdcall GetResult(int stringLengths, char* string1, char* string2, char* string3, ...);

The dll will communicate over a serial line and retrieve information that will be filled into the strings. Where the memory needs to be allocated is open for discussion and can be part of the answer.

The background is that we have a VB6 application team that prefers the second method and a C++/C# team that prefers the first method. Last method looks to suit both teams but looks a bit strange to me with so many parameters.

Maybe there are more options. What is common practice under Windows? Any examples from the Windows API or arguments to choose one over the other?

Edit: The strings have a meaning as in first name, last name, email. We currently have eight, but in the future we might add a couple for example for address. An array would not be the correct choice for this, but that was not clear from the original context.

答:
The best way is probably using a safe array storing BSTR strings.

Both VB and C# understand safe arrays very well: in C#, a safe array of BSTR strings is automatically converted to a string[] array.

On the C++ side, you can use the ATL::CComSafeArray helper class to simplify safe array programming.

You will find interesting material in this MSDN Magazine article (in particular, take a look at the paragraph Producing a Safe Array of Strings).

From the aforementioned article: On the C++ side, you can implement a C-interface DLL, exporting a function like this:

```<code>extern "C" HRESULT MyDllGetStrings(/* [out] */ SAFEARRAY** ppsa)
{
  try {
    // Create a SAFEARRAY containing 'count' BSTR strings
    CComSafeArray<BSTR> sa(count);

    for (LONG i = 0; i < count; i++) {
      // Use ATL::CComBSTR to safely wrap BSTR strings in C++
      CComBSTR bstr = /* your string, may build from std::wstring or CString */ ;

      // Move the the BSTR string into the safe array
      HRESULT hr = sa.SetAt(i, bstr.Detach(), FALSE);

      if (FAILED(hr)) {
        // Error...
        return hr;
      }
    }

    // Return ("move") the safe array to the caller
    // as an output parameter (SAFEARRAY **ppsa)
    *ppsa = sa.Detach();

  } catch (const CAtlException& e) {
    // Convert ATL exceptions to HRESULTs
    return e;
  }

  // All right
  return S_OK;
}
</code>```

On the C# side, you can use this PInvoke declaration:

```<code>[DllImport("MyDll.dll", PreserveSig = false)]
public static extern void MyDllGetStrings(
  [Out, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
  out string[] result);
</code>```

Title: Return multiple strings from dll

Body:
we are having a discussion as what is a good way to return multiple strings from one dll function. Currently we have 8 strings, but there will be more. For simplicity I now consider all strings will have equal lengths.

extern "C" int DLLNAME_ _stdcall GetResult(TestResults* testResults);

where

struct TestResults
{
    int stringLengths;
    char* string1;
    char* string2;
    char* string3;
    char* string4;
    ...
};

or second option: where

struct TestResults
{
    int stringLengths;
    char string1[64];
    char string2[64];
    char string3[64];
    char string4[64];
    ...
};

third option:
extern "C" int DLLNAME_ _stdcall GetResult(int stringLengths, char* string1, char* string2, char* string3, ...);

The dll will communicate over a serial line and retrieve information that will be filled into the strings. Where the memory needs to be allocated is open for discussion and can be part of the answer.

The background is that we have a VB6 application team that prefers the second method and a C++/C# team that prefers the first method. Last method looks to suit both teams but looks a bit strange to me with so many parameters.

Maybe there are more options. What is common practice under Windows? Any examples from the Windows API or arguments to choose one over the other?

Edit: The strings have a meaning as in first name, last name, email. We currently have eight, but in the future we might add a couple for example for address. An array would not be the correct choice for this, but that was not clear from the original context.

Body:
The best way is probably using a safe array storing BSTR strings.

Both VB and C# understand safe arrays very well: in C#, a safe array of BSTR strings is automatically converted to a string[] array.

On the C++ side, you can use the ATL::CComSafeArray helper class to simplify safe array programming.

You will find interesting material in this MSDN Magazine article (in particular, take a look at the paragraph Producing a Safe Array of Strings).

From the aforementioned article: On the C++ side, you can implement a C-interface DLL, exporting a function like this:

extern "C" HRESULT MyDllGetStrings(/* [out] */ SAFEARRAY** ppsa)
{
  try {
    // Create a SAFEARRAY containing 'count' BSTR strings
    CComSafeArray<BSTR> sa(count);

    for (LONG i = 0; i < count; i++) {
      // Use ATL::CComBSTR to safely wrap BSTR strings in C++
      CComBSTR bstr = /* your string, may build from std::wstring or CString */ ;

      // Move the the BSTR string into the safe array
      HRESULT hr = sa.SetAt(i, bstr.Detach(), FALSE);

      if (FAILED(hr)) {
        // Error...
        return hr;
      }
    }

    // Return ("move") the safe array to the caller
    // as an output parameter (SAFEARRAY **ppsa)
    *ppsa = sa.Detach();

  } catch (const CAtlException& e) {
    // Convert ATL exceptions to HRESULTs
    return e;
  }

  // All right
  return S_OK;
}

On the C# side, you can use this PInvoke declaration:

[DllImport("MyDll.dll", PreserveSig = false)]
public static extern void MyDllGetStrings(
  [Out, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
  out string[] result);


问:
Why does this Javascript example copy the variable value instead of pass by reference?
In Javascript The Good Parts, it states:

So I would expect the following code example to output 1001 since "objects are never copied but passed around by reference", so why does it output 0000?

```<code>var page_item = {
  id_code : 'welcome',
  title : 'Welcome',
  access_groups : {
      developer : '0010',
      administrator : '0100'
  }
};
page_item.access_groups.member = '0000';
var member = page_item.access_groups.member;
member = '1001';

$('p#test').html(page_item.access_groups.member); //should be "1001" but is "0000"
</code>```

Added:

@Gareth @David, thanks, this is what I was trying to show in this example, works:

```<code>var page_item = {
  id_code : 'welcome',
  title : 'Welcome',
  access_groups : {
      developer : '0010',
      administrator : '0100'
  }
};
var page_item2 = page_item;
page_item2.access_groups.developer = '1001';

$('p#test').html(page_item.access_groups.developer); //is '1001'
</code>```

答: Because page_item.access_groups.member is a string and not an Object.

Body:
In Javascript The Good Parts, it states:

So I would expect the following code example to output 1001 since "objects are never copied but passed around by reference", so why does it output 0000?

var page_item = {
  id_code : 'welcome',
  title : 'Welcome',
  access_groups : {
      developer : '0010',
      administrator : '0100'
  }
};
page_item.access_groups.member = '0000';
var member = page_item.access_groups.member;
member = '1001';

$('p#test').html(page_item.access_groups.member); //should be "1001" but is "0000"

Added:

@Gareth @David, thanks, this is what I was trying to show in this example, works:

var page_item = {
  id_code : 'welcome',
  title : 'Welcome',
  access_groups : {
      developer : '0010',
      administrator : '0100'
  }
};
var page_item2 = page_item;
page_item2.access_groups.developer = '1001';

$('p#test').html(page_item.access_groups.developer); //is '1001'