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

```<code>  **ListView**
         **TextView**
         **TextView**
         **ListView**(i have used Linear layout in here)
</code>```

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

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

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

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

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

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

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

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

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

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

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

                        </TextView>

                    </LinearLayout>

////this is the replacement of ListView in Inner
                    <LinearLayout
                        android:id="@+id/student_profile_fee_linearlayout1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

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

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

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

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

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

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

                    </LinearLayout>

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

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

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

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

                    </LinearLayout>

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

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

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

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

                    </LinearLayout>
                </LinearLayout>

            </LinearLayout>

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

        </LinearLayout>
</LinearLayout>
</code>```

student_fees_listview

```<code><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#2E353D"
        android:orientation="vertical">

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

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

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

        </LinearLayout>
    </LinearLayout>

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

        />

</LinearLayout>
</code>```

CustomFeeListStudentAdapter

```<code>public class CustomFeeListStudentAdapter extends BaseAdapter {

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

    Context mContext;

    ArrayList<StudentFeeInformation> student_list;
    String TAG = "HomeTab_adapter";

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

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

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

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

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

            // well set up the ViewHolder
            viewHolder = new Holder();
            viewHolder.student_profile_fee_status = (TextView) convertView.findViewById(R.id.student_profile_fee_status);
            viewHolder.student_profile_ReceiptIssuedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedDate);
            viewHolder.student_profile_ReceiptIssuedNumber = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedNumber);
            viewHolder.student_profile_FeeReceivedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_FeeReceiptDate);
            viewHolder.student_profile_Fee_Amount = (TextView) convertView.findViewById(R.id.student_profile_fee_amount);
            viewHolder.student_profile_Fee_Description = (TextView) convertView.findViewById(R.id.student_profile_fee_description);

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

        viewHolder.student_profile_fee_status.setText(student_list.get(postion).getStatus());
        viewHolder.student_profile_ReceiptIssuedDate.setText(student_list.get(postion).getReceiptIssuedDate());
        viewHolder.student_profile_ReceiptIssuedNumber.setText(student_list.get(postion).getReceiptIssuedNumber());
        viewHolder.student_profile_FeeReceivedDate.setText(student_list.get(postion).getFeeReceivedDate());

        viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());

        viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());

        convertView.setTag(viewHolder);
        return convertView;
    }

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

    }
}
</code>```

Fee

```<code>public class Fee extends Fragment /*implements View.OnClickListener   */ {

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

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

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

    LinearLayout linearLayout;

    //   View view1;

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

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

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

        setHasOptionsMenu(true);
        receipt1 = (LinearLayout) view.findViewById(R.id.linear_receipt1_fee);

        //  receipt4 = (LinearLayout) view.findViewById(R.id.linear_receipt4_fee);

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

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

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

        statustextView = (TextView) view.findViewById(R.id.student_profile_fee_status);
        SessionManagement sessionManagement = new SessionManagement(getContext());
        master_id = sessionManagement.getMasterId();
        listViewfees = (ListView) view.findViewById(R.id.list_student_fees);
        // listviewfeedetail = (ListView) view.findViewById(R.id.listtest);

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

        getUsersListData();

        return view;
    }

    private void getUsersListData() {

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

                            ArrayList<StudentFeeInformation> student_list = new ArrayList<>();
                            ArrayList<FeeDescriptionStudent> student_list_description = new ArrayList<>();

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

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

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

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

                                    JSONObject jsonObjectinner = jArray1.getJSONObject(j);
                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");

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

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

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

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

                                }

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

                            }

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

                        } catch (JSONException e) {

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

                            e.printStackTrace();

                        }

                    }

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

            }
        }) {

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

        };

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

    }

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

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

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

logcat

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

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

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

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

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

      JSONObject jsonObjectinner = jArray1.getJSONObject(j);

      Descriptionlist = jsonObjectinner.getString("des");

      Amount = jsonObjectinner.getString("Amount");

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

     }
</code>```

Layout:

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

In Adapter:

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

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

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

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

Title: Alternative of List Within List?

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

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

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

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

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

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

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

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

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

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

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

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

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

                        </TextView>

                    </LinearLayout>

////this is the replacement of ListView in Inner
                    <LinearLayout
                        android:id="@+id/student_profile_fee_linearlayout1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

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

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

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

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

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

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

                    </LinearLayout>

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

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

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

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

                    </LinearLayout>

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

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

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

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

                    </LinearLayout>
                </LinearLayout>

            </LinearLayout>

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

        </LinearLayout>
</LinearLayout>

student_fees_listview

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#2E353D"
        android:orientation="vertical">

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

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

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

        </LinearLayout>
    </LinearLayout>

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

        />

</LinearLayout>

CustomFeeListStudentAdapter

public class CustomFeeListStudentAdapter extends BaseAdapter {

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

    Context mContext;

    ArrayList<StudentFeeInformation> student_list;
    String TAG = "HomeTab_adapter";

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

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

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

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

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

            // well set up the ViewHolder
            viewHolder = new Holder();
            viewHolder.student_profile_fee_status = (TextView) convertView.findViewById(R.id.student_profile_fee_status);
            viewHolder.student_profile_ReceiptIssuedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedDate);
            viewHolder.student_profile_ReceiptIssuedNumber = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedNumber);
            viewHolder.student_profile_FeeReceivedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_FeeReceiptDate);
            viewHolder.student_profile_Fee_Amount = (TextView) convertView.findViewById(R.id.student_profile_fee_amount);
            viewHolder.student_profile_Fee_Description = (TextView) convertView.findViewById(R.id.student_profile_fee_description);

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

        viewHolder.student_profile_fee_status.setText(student_list.get(postion).getStatus());
        viewHolder.student_profile_ReceiptIssuedDate.setText(student_list.get(postion).getReceiptIssuedDate());
        viewHolder.student_profile_ReceiptIssuedNumber.setText(student_list.get(postion).getReceiptIssuedNumber());
        viewHolder.student_profile_FeeReceivedDate.setText(student_list.get(postion).getFeeReceivedDate());

        viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());

        viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());

        convertView.setTag(viewHolder);
        return convertView;
    }

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

    }
}

Fee

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

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

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

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

    LinearLayout linearLayout;

    //   View view1;

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

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

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

        setHasOptionsMenu(true);
        receipt1 = (LinearLayout) view.findViewById(R.id.linear_receipt1_fee);

        //  receipt4 = (LinearLayout) view.findViewById(R.id.linear_receipt4_fee);

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

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

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

        statustextView = (TextView) view.findViewById(R.id.student_profile_fee_status);
        SessionManagement sessionManagement = new SessionManagement(getContext());
        master_id = sessionManagement.getMasterId();
        listViewfees = (ListView) view.findViewById(R.id.list_student_fees);
        // listviewfeedetail = (ListView) view.findViewById(R.id.listtest);

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

        getUsersListData();

        return view;
    }

    private void getUsersListData() {

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

                            ArrayList<StudentFeeInformation> student_list = new ArrayList<>();
                            ArrayList<FeeDescriptionStudent> student_list_description = new ArrayList<>();

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

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

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

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

                                    JSONObject jsonObjectinner = jArray1.getJSONObject(j);
                                    Descriptionlist = jsonObjectinner.getString("des");
                                    Amount = jsonObjectinner.getString("Amount");

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

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

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

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

                                }

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

                            }

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

                        } catch (JSONException e) {

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

                            e.printStackTrace();

                        }

                    }

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

            }
        }) {

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

        };

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

    }

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

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

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

logcat

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

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

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

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

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

      JSONObject jsonObjectinner = jArray1.getJSONObject(j);

      Descriptionlist = jsonObjectinner.getString("des");

      Amount = jsonObjectinner.getString("Amount");

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

     }

Layout:

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

In Adapter:

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

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

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

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


来源: stackexchange

问:
Date format not working correctly
Im submitting a form that has a date range picker in it.

I have the code to get the value of the picker from the form, which is in this format:

```<code>01/03/2017 - 01/03/2017
</code>```

I also have it so that it splits the date range into two variables.

```<code>$one = 20/01/2017
$two = 13/03/2017
</code>```

Im now trying to format the date of these variables into the one that MYSQL uses.

My problem is that the end date will fail and be displayed as 1970-01-01 all the time.

```<code>// Get the range from the form
$daterange = $_POST["daterange"];

// Split the range into a start and end date
list($one, $two) = explode("-", "$daterange", 2);

// Test the split worked
echo $one;
echo $two;

// Format the start date into MySQL style
$StartDate = date("Y-m-d", strtotime($one));

// Test date
echo $StartDate;

// Format the end date into MySQL style
$EndDate = date("Y-m-d", strtotime($two));

//Test date
echo $EndDate;
</code>```

答:
Use this to format your date:

```<code>$StartDate = date_format(date_create_from_format('d/m/Y', $one), 'Y-m-d');
</code>```

To reverse:

```<code>$reverse = date('d/m/Y', strtotime($StartDate));
</code>```

ContentLicense: CC BY-SA 3.0

Title: Date format not working correctly

Body:
Im submitting a form that has a date range picker in it.

I have the code to get the value of the picker from the form, which is in this format:

01/03/2017 - 01/03/2017

I also have it so that it splits the date range into two variables.

$one = 20/01/2017
$two = 13/03/2017

Im now trying to format the date of these variables into the one that MYSQL uses.

My problem is that the end date will fail and be displayed as 1970-01-01 all the time.

// Get the range from the form
$daterange = $_POST["daterange"];

// Split the range into a start and end date
list($one, $two) = explode("-", "$daterange", 2);

// Test the split worked
echo $one;
echo $two;

// Format the start date into MySQL style
$StartDate = date("Y-m-d", strtotime($one));

// Test date
echo $StartDate;

// Format the end date into MySQL style
$EndDate = date("Y-m-d", strtotime($two));

//Test date
echo $EndDate;

Body:
Use this to format your date:

$StartDate = date_format(date_create_from_format('d/m/Y', $one), 'Y-m-d');

To reverse:

$reverse = date('d/m/Y', strtotime($StartDate));


问:
When migrating from Angular 1.5 to 1.6 routing is ran inside unit tests
I've migrated my app to Angular 1.6 and suddenly unit test aren't working anymore. After investigating a little I found out that routing is enabled when running unit tests.

The code that I have added extra to the $routeProvider is this one:

$routeProvider.whenAuthenticated = function (path, route) {
    route.resolve = route.resolve || {};

    angular.extend(route.resolve, {
        isAuthenticated: ['Auth', function (auth) {
             return auth.authenticate();
        }]
    });

    return $routeProvider.when(path, route);
};```
</div>
</div>
</p>

<p>and</p>

```$routeProvider
    .whenAuthenticated('/', {
        redirectTo: '/dashboards'
    });
```

In Angular 1.5 the auth.authenticate() is never hit, while in Angular 1.6 the app tries to navigate to one of my routes and then auth.authenticate() is hit, and the url changes to "/dashboards".
Does anybody have an idea about what changed in 1.6? Do I need to do something extra to disable routing while testing?

答:
In 1.6 the way the $route service and its dependencies are instantiated has changed, and will - by default - be instantiated early on.

Migrating from Previous Versions

Body:
I've migrated my app to Angular 1.6 and suddenly unit test aren't working anymore. After investigating a little I found out that routing is enabled when running unit tests.

The code that I have added extra to the $routeProvider is this one:

$routeProvider.whenAuthenticated = function (path, route) {
    route.resolve = route.resolve || {};

    angular.extend(route.resolve, {
        isAuthenticated: ['Auth', function (auth) {
             return auth.authenticate();
        }]
    });

    return $routeProvider.when(path, route);
};

and

$routeProvider
    .whenAuthenticated('/', {
        redirectTo: '/dashboards'
    });

In Angular 1.5 the auth.authenticate() is never hit, while in Angular 1.6 the app tries to navigate to one of my routes and then auth.authenticate() is hit, and the url changes to "/dashboards".
Does anybody have an idea about what changed in 1.6? Do I need to do something extra to disable routing while testing?


问:
Django dropped table still exists
Having problems with a model in one of my django apps.

I can make an instance of the model, but when I go to access it, I get an error:

```<code># create and save model instance
user_form = UserSearchForm(user=user)
user_form.save()

# Then later
first_user_form = UserSearchForm.objects.all()[0]

(1146, "Table 'project.app_tablename' doesn't exist")
Request Method: GET
Request URL:    http://10.0.75.1:8000/search/
Django Version: 1.9.5
Exception Type: ProgrammingError
Exception Value:
(1146, "Table 'project.app_tablename' doesn't exist")
Exception Location: /opt/project-venv/lib/python3.4/site-packages/MySQLdb/connections.py in query, line 280
Python Executable:  /opt/project-venv/bin/python
Python Version: 3.4.3
Python Path:
['/opt/project/project',
 '/opt/project-venv/lib64/python34.zip',
 '/opt/project-venv/lib64/python3.4',
 '/opt/project-venv/lib64/python3.4/plat-linux',
 '/opt/project-venv/lib64/python3.4/lib-dynload',
 '/usr/lib64/python3.4',
 '/usr/lib/python3.4',
 '/opt/project-venv/lib/python3.4/site-packages']
Server time:    Tue, 28 Mar 2017 22:50:16 +0000
</code>```

I'm using Django 1.95 and I tried the following from the linked answer (https://stackoverflow.com/a/36565161/2516846):

Delete app migrations folder

Drop all app tables, e.g. DROP TABLE search_usersearchform

Delete all migrations from db: DELETE FROM django_migrations WHERE app = 'search'.

python manage.py makemigrations search

python manage.py migrate

But when I run migrate, it gives error:

```<code>django.db.utils.ProgrammingError: relation "search_usersearchform" already exists
</code>```

Summary: Cannot create model again as relation already exists, yet cannot access model in my app as it says table doesn't exist

Is there a reference to this table/model stored else where which I need to remove? I don't know how the relation can already exist if I dropped the table, deleted migrations folder and removed migrations from db

EDIT

Okay finally got this sorted.

My project had two databases, the 'default' db, using postgres, and the 'secondary' db, using mysql.

When I created a new model in my app, and ran the migration, the table was added to the default db.

This allowed me to create an instance of the new model.

However when I went to access a previously saved instance, I got the error saying the table does not exist.

Turns out it was caused by my apps router.py, which redirected any queries to the 'secondary' db, which of course did not have the table.

To fix this, I added conditionals to the db_for_write and db_for_read methods in  router.py, to route those models to the 'default' db.

答:
Following these steps should fix it:

Remove the database.

Create an empty one with the same name.

Optionally, you may need to create a superuser for the new database.

Remove the content of package migrations (not the entire package), except file init.py.

Run command python manage.py makemigrations

Run command python manage.py migrate

Title: Django dropped table still exists

Body:
Having problems with a model in one of my django apps.

I can make an instance of the model, but when I go to access it, I get an error:

# create and save model instance
user_form = UserSearchForm(user=user)
user_form.save()

# Then later
first_user_form = UserSearchForm.objects.all()[0]

(1146, "Table 'project.app_tablename' doesn't exist")
Request Method: GET
Request URL:    http://10.0.75.1:8000/search/
Django Version: 1.9.5
Exception Type: ProgrammingError
Exception Value:
(1146, "Table 'project.app_tablename' doesn't exist")
Exception Location: /opt/project-venv/lib/python3.4/site-packages/MySQLdb/connections.py in query, line 280
Python Executable:  /opt/project-venv/bin/python
Python Version: 3.4.3
Python Path:
['/opt/project/project',
 '/opt/project-venv/lib64/python34.zip',
 '/opt/project-venv/lib64/python3.4',
 '/opt/project-venv/lib64/python3.4/plat-linux',
 '/opt/project-venv/lib64/python3.4/lib-dynload',
 '/usr/lib64/python3.4',
 '/usr/lib/python3.4',
 '/opt/project-venv/lib/python3.4/site-packages']
Server time:    Tue, 28 Mar 2017 22:50:16 +0000

I'm using Django 1.95 and I tried the following from the linked answer (https://stackoverflow.com/a/36565161/2516846):

Delete app migrations folder

Drop all app tables, e.g. DROP TABLE search_usersearchform

Delete all migrations from db: DELETE FROM django_migrations WHERE app = 'search'.

python manage.py makemigrations search

python manage.py migrate

But when I run migrate, it gives error:

django.db.utils.ProgrammingError: relation "search_usersearchform" already exists

Summary: Cannot create model again as relation already exists, yet cannot access model in my app as it says table doesn't exist

Is there a reference to this table/model stored else where which I need to remove? I don't know how the relation can already exist if I dropped the table, deleted migrations folder and removed migrations from db

EDIT

Okay finally got this sorted.

My project had two databases, the 'default' db, using postgres, and the 'secondary' db, using mysql.

When I created a new model in my app, and ran the migration, the table was added to the default db.

This allowed me to create an instance of the new model.

However when I went to access a previously saved instance, I got the error saying the table does not exist.

Turns out it was caused by my apps router.py, which redirected any queries to the 'secondary' db, which of course did not have the table.

To fix this, I added conditionals to the db_for_write and db_for_read methods in  router.py, to route those models to the 'default' db.


问:
Divide whole canvas in equal columns
I am trying to divide my whole canvas in 20 equal columns and animate them individually on the y-axis. The goal is to create a similar wave scroll animation like here. First I tried to create the wave scroll effect with php generated images with the text on it and tried to animate them in single divs with the images as background-images. It technically worked but the performance and page load time was extremely bad. Now I want to create it with canvas: I already have the content with all the images and text in it and tried to animate it. I tried to save the whole content in columns (rectangles) with getImageData() then I created created rectangles with the ImageData and re-draw them in a loop but again the performance was terrible, especially on mobile devices. The animation loop looked as followed:

```<code>var animate = function(index, y) {
  // The calculations required for the step function
  var start = new Date().getTime();
  var end = start + duration;
  var current = rectangles[index].y;
  var distance = y - current;
  var step = function() {
    // get our current progress
    var timestamp = new Date().getTime();
    var progress = Math.min((duration - (end - timestamp)) / duration, 1);
    context.clearRect(rectangles[index].x, rectangles[index].y, columnWidth, canvas.height);
    // update the rectangles y property
    rectangles[index].y = current + (distance * progress);
    context.putImageData(rectangles[index].imgData, rectangles[index].x, rectangles[index].y);
    // if animation hasn't finished, repeat the step.
    if (progress < 1)
      requestAnimationFrame(step);
  };
  // start the animation
  return step();
};
</code>```

Now the question: How can I divide the whole canvas in equal columns and animate them on the y-axis with a good performance? Any suggestions? Maybe with the help of Pixi.js / Greensock? Thanks in advance!

答:
Do not use getImageData and setImageData to do animation. The canvas is an image and can be rendered just like any image.

To do what you want

Create a second copy of the canvas and use that canvas a source for the strips you want to render.

Example.

const slices = 20;
var widthStep;
var canvas = document.createElement("canvas");
var canvas1 = document.createElement("canvas");
canvas.style.position = "absolute";
canvas.style.top = canvas.style.left = "0px";

var ctx = canvas.getContext("2d");
var ctx1 = canvas1.getContext("2d");
var w = canvas.width;
var h = canvas.height;
function resize(){
    canvas.width = canvas1.width = innerWidth;
    canvas.height = canvas1.height = innerHeight;
    w = canvas.width;
    h = canvas.height;
    ctx1.font = "64px arial black";
    ctx1.textAlign = "center"
    ctx1.textBaseLine = "middle";
    ctx1.fillStyle = "blue";
    ctx1.fillRect(0,0,w,h);
    ctx1.fillStyle = "red";
    ctx1.fillRect(50,50,w-100,h-100);
    ctx1.fillStyle = "black";
    ctx1.strokeStyle = "white";
    ctx1.lineWidth = 5;
    ctx1.lineJoin = "round";
    ctx1.strokeText("Waves and canvas",w / 2, h / 2);
    ctx1.fillText("Waves and canvas",w / 2, h / 2);
    widthStep = Math.ceil(w / slices);
}
resize();
window.addEventListener("resize",resize);
document.body.appendChild(canvas);
function update(time){
    var y;
    var x = 0;
    ctx.clearRect(0,0,canvas.width,canvas.height);
    for(var i = 0; i < slices; i ++){
        y = Math.sin(time / 500 + i / 5) * (w / 8);
        y += Math.sin(time / 700 + i / 7) * (w / 13);
        y += Math.sin(time / 300 + i / 3) * (w / 17);
        ctx.drawImage(canvas1,x,0,widthStep,h,x,y,widthStep,h);
        x += widthStep;
     }
     requestAnimationFrame(update);
}
requestAnimationFrame(update);```

Title: Divide whole canvas in equal columns

Body:
I am trying to divide my whole canvas in 20 equal columns and animate them individually on the y-axis. The goal is to create a similar wave scroll animation like here. First I tried to create the wave scroll effect with php generated images with the text on it and tried to animate them in single divs with the images as background-images. It technically worked but the performance and page load time was extremely bad. Now I want to create it with canvas: I already have the content with all the images and text in it and tried to animate it. I tried to save the whole content in columns (rectangles) with getImageData() then I created created rectangles with the ImageData and re-draw them in a loop but again the performance was terrible, especially on mobile devices. The animation loop looked as followed:

var animate = function(index, y) {
  // The calculations required for the step function
  var start = new Date().getTime();
  var end = start + duration;
  var current = rectangles[index].y;
  var distance = y - current;
  var step = function() {
    // get our current progress
    var timestamp = new Date().getTime();
    var progress = Math.min((duration - (end - timestamp)) / duration, 1);
    context.clearRect(rectangles[index].x, rectangles[index].y, columnWidth, canvas.height);
    // update the rectangles y property
    rectangles[index].y = current + (distance * progress);
    context.putImageData(rectangles[index].imgData, rectangles[index].x, rectangles[index].y);
    // if animation hasn't finished, repeat the step.
    if (progress < 1)
      requestAnimationFrame(step);
  };
  // start the animation
  return step();
};

Now the question: How can I divide the whole canvas in equal columns and animate them on the y-axis with a good performance? Any suggestions? Maybe with the help of Pixi.js / Greensock? Thanks in advance!


问:
How can we add background music in swift playground?(using AVFoundation)
Through music is playing perfectly but I am not able to execute my main programme.

```<code>import UIKit
import AVFoundation

print("Hello, Audio!")

if let url = Bundle.main.url(forResource: "drum01", withExtension: "mp3") {
    do {
        let midi = try AVMIDIPlayer(contentsOf: url, soundBankURL: nil)
        midi.play(nil)
        while midi.isPlaying {
            // Spin (yeah, that's bad!)
        }
    } catch (let error) {
        print("AVMIDIPlayer failed: " + error.localizedDescription)
    }
}
</code>```

Any help will be appreciated.

答:
do you add "mySound" to your project?

And what type of "mySound" ->  ofType: "mySound"

sample: ofType: "mp3"

Body:
Through music is playing perfectly but I am not able to execute my main programme.

import UIKit
import AVFoundation

print("Hello, Audio!")

if let url = Bundle.main.url(forResource: "drum01", withExtension: "mp3") {
    do {
        let midi = try AVMIDIPlayer(contentsOf: url, soundBankURL: nil)
        midi.play(nil)
        while midi.isPlaying {
            // Spin (yeah, that's bad!)
        }
    } catch (let error) {
        print("AVMIDIPlayer failed: " + error.localizedDescription)
    }
}

Any help will be appreciated.


问:
pandas apply a new column
I have a dataframe like this:

```<code>import pandas as pd
import numpy as np
df=pd.DataFrame({'c1':[1,2,4,5],
                'c2':[3,'P','N','T'],
                'c3':np.nan})
</code>```

the df:

```<code>   c1   c2  c3
0   1   3   NaN
1   2   P   NaN
2   4   N   NaN
3   5   T   NaN
</code>```

I want to change the c3 value based on c2 columns:

the result I wanted:

```<code>    c1  c2  c3
 0  1   3   NaN
 1  2   P   1.0
 2  4   N   3.0
 3  5   T   5.0
</code>```

I use the concat to get this result:

```<code>df1=df[df.c2 == 'P']
df1['c3'] =1
df2=df[df.c2 == 'N']
df2['c3'] =3
df3=df[df.c2 == 'T']
df3['c3'] =5
df4=df[(df.c2 != 'N') & (df.c2 != 'P') & (df.c2 != 'T')]
new_df=pandas.concat([df1,df2,df3,df4]).reset_index()
new_df[['c1','c2','c3']]
</code>```

I want to use apply function to get the same result. I always replace the whole c3 columns when I use apply function:

```<code>def new_col(x,df):

    if x== 'P':
        df['c3'] = 1
    elif x == 'N':
        df['c3'] = 3
    elif x == 'T':
        df['c3'] =5
    else:
        df['c3']=np.nan
df.c2.apply(new_col,df=df)
df
</code>```

How I change the new_col function ?

答:
You can use:

```<code>def new_col(x):
    a = np.nan
    if x == 'P':
        a = 1
    elif x == 'N':
        a = 3
    elif x == 'T':
       a = 5
    return a

df['c3'] = df.c2.apply(new_col)
print (df)
   c1 c2   c3
0   1  3  NaN
1   2  P  1.0
2   4  N  3.0
3   5  T  5.0
</code>```

Another solution:

```<code>df.loc[df.c2 == 'P', 'C3'] = 1
df.loc[df.c2 == 'N', 'C3'] = 3
df.loc[df.c2 == 'T', 'C3'] = 5
print (df)
   c1 c2  c3   C3
0   1  3 NaN  NaN
1   2  P NaN  1.0
2   4  N NaN  3.0
3   5  T NaN  5.0
</code>```

Title: pandas apply a new column

Body:
I have a dataframe like this:

import pandas as pd
import numpy as np
df=pd.DataFrame({'c1':[1,2,4,5],
                'c2':[3,'P','N','T'],
                'c3':np.nan})

the df:

   c1   c2  c3
0   1   3   NaN
1   2   P   NaN
2   4   N   NaN
3   5   T   NaN

I want to change the c3 value based on c2 columns:

the result I wanted:

    c1  c2  c3
 0  1   3   NaN
 1  2   P   1.0
 2  4   N   3.0
 3  5   T   5.0

I use the concat to get this result:

df1=df[df.c2 == 'P']
df1['c3'] =1
df2=df[df.c2 == 'N']
df2['c3'] =3
df3=df[df.c2 == 'T']
df3['c3'] =5
df4=df[(df.c2 != 'N') & (df.c2 != 'P') & (df.c2 != 'T')]
new_df=pandas.concat([df1,df2,df3,df4]).reset_index()
new_df[['c1','c2','c3']]

I want to use apply function to get the same result. I always replace the whole c3 columns when I use apply function:

def new_col(x,df):

    if x== 'P':
        df['c3'] = 1
    elif x == 'N':
        df['c3'] = 3
    elif x == 'T':
        df['c3'] =5
    else:
        df['c3']=np.nan
df.c2.apply(new_col,df=df)
df

How I change the new_col function ?

Body:
You can use:

def new_col(x):
    a = np.nan
    if x == 'P':
        a = 1
    elif x == 'N':
        a = 3
    elif x == 'T':
       a = 5
    return a

df['c3'] = df.c2.apply(new_col)
print (df)
   c1 c2   c3
0   1  3  NaN
1   2  P  1.0
2   4  N  3.0
3   5  T  5.0

Another solution:

df.loc[df.c2 == 'P', 'C3'] = 1
df.loc[df.c2 == 'N', 'C3'] = 3
df.loc[df.c2 == 'T', 'C3'] = 5
print (df)
   c1 c2  c3   C3
0   1  3 NaN  NaN
1   2  P NaN  1.0
2   4  N NaN  3.0
3   5  T NaN  5.0


问:
Codeigniter file upload displaying error
Controller code

```<code>        $config['upload_path']          = './uploads/'.$random;
        $config['allowed_types']        = 'gif|jpg|png';
        $config['max_size']             = 100;
        $config['max_width']            = 1024;
        $config['max_height']           = 768;

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('imageupload'))
        {
            $error = array('error' => $this->upload->display_errors());
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
        }
        print_r($data);
</code>```

HTML code:

```<code><form role="form" enctype="multipart/form-data" accept-charset="utf-8" name="formname" id="formname"  method="post" action="http://www.example.com/Property/post">
    <input type="file" class="default" id="imageupload1" name="imageupload[]">
</form>
</code>```

Whenever I am uploading file it displaying warning is_uploaded_file() expects parameter 1 to be string, array given. How can I resolve it?

答:
try this</p>

```<code>      //place this code in your function for multiple image upload
   $data = array();
    if(!empty($_FILES['imageupload']['name']))
    {
        $filesCount = count($_FILES['imageupload']['name']);
          for($i = 0; $i < $filesCount; $i++){
            $_FILES['imageupload']['name'] = $_FILES['imageupload']['name'][$i];
            $_FILES['imageupload']['type'] = $_FILES['imageupload']['type'][$i];
            $_FILES['imageupload']['tmp_name'] = $_FILES['imageupload']['tmp_name'][$i];
            $_FILES['imageupload']['error'] = $_FILES['imageupload']['error'][$i];
            $_FILES['imageupload']['size'] = $_FILES['imageupload']['size'][$i];

            $uploadPath = 'uploads/';
            $config['upload_path'] = $uploadPath;
            $config['allowed_types'] = 'gif|jpg|png';

            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if($this->upload->do_upload('imageupload')){
                $fileData = $this->upload->data();
                $uploadData[$i]['file_name'] = $fileData['file_name'];
                $uploadData[$i]['created'] = date("Y-m-d H:i:s");
                $uploadData[$i]['modified'] = date("Y-m-d H:i:s");
            }
        }

        if(!empty($uploadData)){
            //Insert file  into the database using your model

        }
        }
</code>```

Body:
Controller code

        $config['upload_path']          = './uploads/'.$random;
        $config['allowed_types']        = 'gif|jpg|png';
        $config['max_size']             = 100;
        $config['max_width']            = 1024;
        $config['max_height']           = 768;

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('imageupload'))
        {
            $error = array('error' => $this->upload->display_errors());
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
        }
        print_r($data);

HTML code:

<form role="form" enctype="multipart/form-data" accept-charset="utf-8" name="formname" id="formname"  method="post" action="http://www.example.com/Property/post">
    <input type="file" class="default" id="imageupload1" name="imageupload[]">
</form>

Whenever I am uploading file it displaying warning is_uploaded_file() expects parameter 1 to be string, array given. How can I resolve it?

Body:
try this

      //place this code in your function for multiple image upload
   $data = array();
    if(!empty($_FILES['imageupload']['name']))
    {
        $filesCount = count($_FILES['imageupload']['name']);
          for($i = 0; $i < $filesCount; $i++){
            $_FILES['imageupload']['name'] = $_FILES['imageupload']['name'][$i];
            $_FILES['imageupload']['type'] = $_FILES['imageupload']['type'][$i];
            $_FILES['imageupload']['tmp_name'] = $_FILES['imageupload']['tmp_name'][$i];
            $_FILES['imageupload']['error'] = $_FILES['imageupload']['error'][$i];
            $_FILES['imageupload']['size'] = $_FILES['imageupload']['size'][$i];

            $uploadPath = 'uploads/';
            $config['upload_path'] = $uploadPath;
            $config['allowed_types'] = 'gif|jpg|png';

            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if($this->upload->do_upload('imageupload')){
                $fileData = $this->upload->data();
                $uploadData[$i]['file_name'] = $fileData['file_name'];
                $uploadData[$i]['created'] = date("Y-m-d H:i:s");
                $uploadData[$i]['modified'] = date("Y-m-d H:i:s");
            }
        }

        if(!empty($uploadData)){
            //Insert file  into the database using your model

        }
        }


问:
Storing incorrect passwords on .txt file - Python 2.7
I am creating a python program which stores it in a list, then records in a text file called wrongpasswords.txt.

The program should ask the user for input by saying 'Please enter your password: '. The correct password will always be 'rusty' but the user can of course enter any String. And also, how do I add to my program that the number of characters the user inputs wrong is also stored for each incorrect password?

Please do mind me as I am a beginner in programming and python.

Please see my code below:

```<code>enteredPass = raw_input("Enter your password: ")
incorrectPass= file("wrongpasswords.txt","w")
counter = 0

for i in range(0, counter+1):

    if enteredPass != "rusty":
        counter = counter +1
        incorrectPassO = open("wrongpasswords.txt","w")
        incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
        incorrectPassO.close()
        enteredPass = raw_input("Enter your password: ")

    else:
        incorrectPassO = open("wrongpasswords.txt","w")

        incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
        incorrectPassO.close()
</code>```

答:
If I understood correctly you're trying to create a simple login program that counts the wrong login attempts? This should work:

```<code>counter = 0
correct_answer_entered = False

while not correct_answer_entered:
    enteredPass = raw_input("Enter your password: ")
    counter = counter + 1

    if enteredPass != "rusty":
        incorrectPassO = open("wrongpasswords.txt","a")
        incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
        incorrectPassO.close()

    else:
        incorrectPassO = open("wrongpasswords.txt","a")
        incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
        incorrectPassO.close()
        correct_answer_entered = True
</code>```

The points I fixed in your code that you should notice:

I replaced the "w" with an "a" where you open the file, since "w" makes it write over what's already wroten in the file, while "a" appends after what's there.

I replaced the for loop with a while, what you did was a range from 0 to 1, so the loop would exit after the first round, I added a boolean value (correct_answer_entered), to indicate if the correct password was entered, and keeps going if it wasn't.

I moved the "counter = counter + 1" outside of the if statement, since the number of attempts is not related to wither the password is correct or not, the way you did it if the password was correct at the first attempt it'd say 0th attempt instead of 1th.

overrall your code is pretty nice and it's good to see new people getting into programming ^.^

Body:
I am creating a python program which stores it in a list, then records in a text file called wrongpasswords.txt.

The program should ask the user for input by saying 'Please enter your password: '. The correct password will always be 'rusty' but the user can of course enter any String. And also, how do I add to my program that the number of characters the user inputs wrong is also stored for each incorrect password?

Please do mind me as I am a beginner in programming and python.

Please see my code below:

enteredPass = raw_input("Enter your password: ")
incorrectPass= file("wrongpasswords.txt","w")
counter = 0

for i in range(0, counter+1):

    if enteredPass != "rusty":
        counter = counter +1
        incorrectPassO = open("wrongpasswords.txt","w")
        incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
        incorrectPassO.close()
        enteredPass = raw_input("Enter your password: ")

    else:
        incorrectPassO = open("wrongpasswords.txt","w")

        incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
        incorrectPassO.close()

Body:
If I understood correctly you're trying to create a simple login program that counts the wrong login attempts? This should work:

counter = 0
correct_answer_entered = False

while not correct_answer_entered:
    enteredPass = raw_input("Enter your password: ")
    counter = counter + 1

    if enteredPass != "rusty":
        incorrectPassO = open("wrongpasswords.txt","a")
        incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
        incorrectPassO.close()

    else:
        incorrectPassO = open("wrongpasswords.txt","a")
        incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
        incorrectPassO.close()
        correct_answer_entered = True

The points I fixed in your code that you should notice:

I replaced the "w" with an "a" where you open the file, since "w" makes it write over what's already wroten in the file, while "a" appends after what's there.

I replaced the for loop with a while, what you did was a range from 0 to 1, so the loop would exit after the first round, I added a boolean value (correct_answer_entered), to indicate if the correct password was entered, and keeps going if it wasn't.

I moved the "counter = counter + 1" outside of the if statement, since the number of attempts is not related to wither the password is correct or not, the way you did it if the password was correct at the first attempt it'd say 0th attempt instead of 1th.

overrall your code is pretty nice and it's good to see new people getting into programming ^.^


问:
Applying ratelimit decorator to auth views.py
I want to rate limit several views in my Django app (login, register_account, password reset, ...). I am already using Django-Ratelimit. But I am unsure how to add this decorator to existing views. Writing my own views and using them in a custom urls.py looks like a lot of boilerplate code just to add some decorators. </p>

答:
You can use decorators directly in your urls.</p>

```<code>url(r'^login/$', ratelimit(key='whatever')(login_func), name='login'),
</code>```

Body:
You can use decorators directly in your urls.

url(r'^login/$', ratelimit(key='whatever')(login_func), name='login'),


问:
flush(), od_flush() works! or not?
I have this code running in a Windows enviroment with Apache2 and PHP5:

```<code><?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set("output_buffering", 0);
ini_set('zlib.output_compression', 0);

if (!ob_get_level()) {
    ob_start();
} else {
   ob_end_clean();
   ob_start();
}

for($x=0;$x<10;$x++){
    echo "<br/> Linea .... ".$x;
    flush();
    ob_flush();
    sleep(2);

}

?>
</code>```

It's works perfect,

Linea 0 (2 seconds)

Linea 1 (2 seconds)

Linea 2 (2 seconds)

...

Linea 9 (2 seconds)

if I run in a Linux with apache2 and PHP7, don't works,

Linea 0

Linea 1

...

Linea 9 (20 seconds)

but I run script ...

```<code>php /var/www/line.php
</code>```

It's works well.

I dont undestand difference? Or what must I change in my configuration?

答:
9 is your last line so obviously it will take 20 seconds.
it waits for action or browser to response until it reaches the time limit in php.ini file which in you case is set to 20 seconds.
This gives the browser time to respond and i would not play with that setting because if you make it low anyone with slow connection will loose the connection </p>

Title: flush(), od_flush() works! or not?

Body:
I have this code running in a Windows enviroment with Apache2 and PHP5:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set("output_buffering", 0);
ini_set('zlib.output_compression', 0);

if (!ob_get_level()) {
    ob_start();
} else {
   ob_end_clean();
   ob_start();
}

for($x=0;$x<10;$x++){
    echo "
 Linea .... ".$x;
    flush();
    ob_flush();
    sleep(2);

}

?>

It's works perfect,

Linea 0 (2 seconds)

Linea 1 (2 seconds)

Linea 2 (2 seconds)

...

Linea 9 (2 seconds)

if I run in a Linux with apache2 and PHP7, don't works,

Linea 0

Linea 1

...

Linea 9 (20 seconds)

but I run script ...

php /var/www/line.php

It's works well.

I dont undestand difference? Or what must I change in my configuration?


问:
Implement Wikitude in Angular 2
I'm trying to implement Wikitude Architect View in Angular 2 using this reference
https://github.com/jinhong-/nativescript-wikitudearchitectview/blob/master/demo/app/main-page.ts
I'm trying to implement this piece of code in an Angular 2 way

import * as app from 'application';
import * as platform from 'platform';
import { Demo } from "./main-view-model";
import { View } from "ui/core/view";
import * as frameModule from 'ui/frame'

function pageLoaded(args) {
  var page = <View>args.object;
  page.bindingContext = new Demo();
  var architectView = page.getViewById<any>("architectView");
  console.log('pageLoaded');
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><page xmlns="http://schemas.nativescript.org/tns.xsd"
      xmlns:ar="nativescript-wikitudearchitectview"
      loaded="pageLoaded">
      <GridLayout rows="*, auto">
        <ar:ArchitectView id="architectView" urlString="http://10.20.30.79:8888" urlLoaded='urlLoaded' urlLoadError='urlLoadError' urlInvoked='urlInvoked'/>
      </GridLayout>
</page></code>```

so far I have :

@Component({
  selector: "my-app",
  templateUrl: "app.xml"
})
export class AppComponent implements OnInit{

  ngOnInit() {
    var page = <View>args.object;
    page.bindingContext = new Demo();
    var architectView = page.getViewById<any>("architectView");
    console.log('pageLoaded');
  }```
<pre class="snippet-code-html lang-html prettyprint-override"><code>      <GridLayout rows="*, auto">
        <ar:ArchitectView id="architectView" urlString="http://10.20.30.79:8888" urlLoaded='urlLoaded' urlLoadError='urlLoadError' urlInvoked='urlInvoked'>
        </ar:ArchitectView>
        <Button row="1" text="hello"></Button>
      </GridLayout></code>```

The main part is converting these 3 lines into Angular 2 format

```<code>var page = <View>args.object;
page.bindingContext = new Demo();
var architectView = page.getViewById<any>("architectView");
</code>```

But I don't know how can I do that.

答:
First, in your html file you'll need to change <ar:ArchitectView to <ArchitectView, and to support that you can add this to main.ts:

```<code>var architectView = require("nativescript-wikitudearchitectview");
registerElement("ArchitectView", () => architectView.ArchitectView);
</code>```

Second, take a look at this page: http://docs.nativescript.org/angular/tutorial/ng-chapter-6 and search for '#email'. So in your view add:

```<code><ArchitectView #architectView
</code>```

And in the component:

```<code>@ViewChild("architectView") architectView: ElementRef;
</code>```

Title: Implement Wikitude in Angular 2

Body:
I'm trying to implement Wikitude Architect View in Angular 2 using this reference
https://github.com/jinhong-/nativescript-wikitudearchitectview/blob/master/demo/app/main-page.ts
I'm trying to implement this piece of code in an Angular 2 way

import * as app from 'application';
import * as platform from 'platform';
import { Demo } from "./main-view-model";
import { View } from "ui/core/view";
import * as frameModule from 'ui/frame'

function pageLoaded(args) {
  var page = <View>args.object;
  page.bindingContext = new Demo();
  var architectView = page.getViewById<any>("architectView");
  console.log('pageLoaded');
}

<page xmlns="http://schemas.nativescript.org/tns.xsd"
      xmlns:ar="nativescript-wikitudearchitectview"
      loaded="pageLoaded">
      <GridLayout rows="*, auto">
        <ar:ArchitectView id="architectView" urlString="http://10.20.30.79:8888" urlLoaded='urlLoaded' urlLoadError='urlLoadError' urlInvoked='urlInvoked'/>
      </GridLayout>
</page>

so far I have :

@Component({
  selector: "my-app",
  templateUrl: "app.xml"
})
export class AppComponent implements OnInit{

  ngOnInit() {
    var page = <View>args.object;
    page.bindingContext = new Demo();
    var architectView = page.getViewById<any>("architectView");
    console.log('pageLoaded');
  }

      <GridLayout rows="*, auto">
        <ar:ArchitectView id="architectView" urlString="http://10.20.30.79:8888" urlLoaded='urlLoaded' urlLoadError='urlLoadError' urlInvoked='urlInvoked'>
        </ar:ArchitectView>
        <Button row="1" text="hello"></Button>
      </GridLayout>

The main part is converting these 3 lines into Angular 2 format

var page = <View>args.object;
page.bindingContext = new Demo();
var architectView = page.getViewById<any>("architectView");

But I don't know how can I do that.

Body:
First, in your html file you'll need to change <ar:ArchitectView to <ArchitectView, and to support that you can add this to main.ts:

var architectView = require("nativescript-wikitudearchitectview");
registerElement("ArchitectView", () => architectView.ArchitectView);

Second, take a look at this page: http://docs.nativescript.org/angular/tutorial/ng-chapter-6 and search for '#email'. So in your view add:

<ArchitectView #architectView

And in the component:

@ViewChild("architectView") architectView: ElementRef;


问:
DataGrid row validation base on other rows
I want to validate a DataGridCell based on values of other DataGridRows in the same DataGrid. But in my inherited MyValidationRule object I can't access all bound items of the DataGrid, but only the current row.

How can I access other bound items of a DataGrid in the Validate() method of a ValidationRule?

答:
You could add a dependency property to your custom ValidationRule class and bind this one to the DataGrid.

It requires some effort though. You need to create a wrapper class that derives from DependencyObject and capture the DataContext using a Freezable. It is all explained in the following TechNet article. Please refer to it.

WPF: Passing a Data Bound Value To a Validation Rule: https://social.technet.microsoft.com/wiki/contents/articles/31422.wpf-passing-a-data-bound-value-to-a-validation-rule.aspx


问:
Jenkins always show success - TestNG, Selenium
I'm new with Jenkins and I have a problem with builds. I'm writing UI tests with Selenium, Java and TestNG.
My problem is that Jenkins always shows Finished: SUCCESS even if some tests fail.

```<code>    ===============================================
    TestAll
    Total tests run: 10, Failures: 1, Skips: 0
    ===============================================

    [SSH] exit-status: 0
    TestNG Reports Processing: START
    Looking for TestNG results report in workspace using pattern: **/testng-results.xml
    Did not find any matching files.
    Started calculate disk usage of build
    Finished Calculation of disk usage of build in 0 seconds
    Started calculate disk usage of workspace
    Finished Calculation of disk usage of workspace in 0 seconds
    Notifying upstream projects of job completion
    No emails were triggered.
    Finished: SUCCESS
</code>```

How can I resolve my problem?

答:
I assume you are building a Maven Project.
To stop a build on test failure, go to the configure part of your project then go to the build section and in "goals & options line" add :

```<code>-Dmaven.test.failure.ignore=false
</code>```

this should stop the build if errors are found.

Body:
I'm new with Jenkins and I have a problem with builds. I'm writing UI tests with Selenium, Java and TestNG.
My problem is that Jenkins always shows Finished: SUCCESS even if some tests fail.

    ===============================================
    TestAll
    Total tests run: 10, Failures: 1, Skips: 0
    ===============================================

    [SSH] exit-status: 0
    TestNG Reports Processing: START
    Looking for TestNG results report in workspace using pattern: **/testng-results.xml
    Did not find any matching files.
    Started calculate disk usage of build
    Finished Calculation of disk usage of build in 0 seconds
    Started calculate disk usage of workspace
    Finished Calculation of disk usage of workspace in 0 seconds
    Notifying upstream projects of job completion
    No emails were triggered.
    Finished: SUCCESS

How can I resolve my problem?

Body:
I assume you are building a Maven Project.
To stop a build on test failure, go to the configure part of your project then go to the build section and in "goals & options line" add :

-Dmaven.test.failure.ignore=false

this should stop the build if errors are found.


问:
How do I programmatically change file permissions?
In Java, I'm dynamically creating a set of files and I'd like to change the file permissions on these files on a linux/unix file system.  I'd like to be able to execute the Java equivalent of chmod. Is that possible Java 5? If so, how?

I know in Java 6 the File object has setReadable()/setWritable() methods. I also know I could make a system call to do this, but I'd like to avoid that if possible.

答:
If you want to set 777 permission to your created file than you can use the following method:</p>

```<code>public void setPermission(File file) throws IOException{
    Set<PosixFilePermission> perms = new HashSet<>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_WRITE);
    perms.add(PosixFilePermission.OWNER_EXECUTE);

    perms.add(PosixFilePermission.OTHERS_READ);
    perms.add(PosixFilePermission.OTHERS_WRITE);
    perms.add(PosixFilePermission.OTHERS_EXECUTE);

    perms.add(PosixFilePermission.GROUP_READ);
    perms.add(PosixFilePermission.GROUP_WRITE);
    perms.add(PosixFilePermission.GROUP_EXECUTE);

    Files.setPosixFilePermissions(file.toPath(), perms);
}
</code>```

OwnerDisplayName: Roy Rico

ContentLicense: CC BY-SA 4.0

LastEditorDisplayName: Roy Rico

Body:
If you want to set 777 permission to your created file than you can use the following method:

public void setPermission(File file) throws IOException{
    Set<PosixFilePermission> perms = new HashSet<>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_WRITE);
    perms.add(PosixFilePermission.OWNER_EXECUTE);

    perms.add(PosixFilePermission.OTHERS_READ);
    perms.add(PosixFilePermission.OTHERS_WRITE);
    perms.add(PosixFilePermission.OTHERS_EXECUTE);

    perms.add(PosixFilePermission.GROUP_READ);
    perms.add(PosixFilePermission.GROUP_WRITE);
    perms.add(PosixFilePermission.GROUP_EXECUTE);

    Files.setPosixFilePermissions(file.toPath(), perms);
}


问:
Firebug css js order vs real load order
I want to know the order firebug shows in script , css.Is it the real order in which
the files are loaded or they are shown in sorted alphabetical order.

I want to know the sequence order how they are loaded instead of doing viewsource.

any inputs will be appreciated.

Thanks.

答: Firebug's Net tab will show you the order in which the browser makes requests. You can filter based on Javascript, CSS, images, etc. This is the "real" order, not alphabetized.

ContentLicense: CC BY-SA 2.5

Title: Firebug css js order vs real load order