问:
display recyclerview checkbox as selected and un-selected based on boolean values android
Let me tell you what exactly I needed. I need to load 20 questions from my MySql DB to recyclerview. Questions are saved in a table that has two columns ie, id and question. I can successfully load these questions to my recyclerview with the help of an adapter. Here is the twist, I need to mark these questions as "Yes" or "No" in my recyclerview by using checkboxes for each based on what exactly logged in user answered before this questions from his profile. Also, I expect good database and object class design solution in order to achieve this.

Here what I have tried,

Adapter Class:

```<code>public class MyHealthInfoAdapter extends RecyclerView.Adapter<MyHealthInfoAdapter.MyHealthViewHolder> {

private Context context;
private ArrayList<DonorHealthStatusQuestionare> listQuestions;

public MyHealthInfoAdapter(Context context, ArrayList<DonorHealthStatusQuestionare> listQuestions) {
    this.context = context;
    this.listQuestions = listQuestions;
}

@Override
public MyHealthViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_my_health_info, parent, false);
    return new MyHealthViewHolder(view);
}

@Override
public void onBindViewHolder(final MyHealthViewHolder holder, int position) {

    DonorHealthStatusQuestionare donorHealthStatusQuestionare = listQuestions.get(position);
    holder.tvQuestion.setText(donorHealthStatusQuestionare.getQuestions());

}

@Override
public int getItemCount() {
    return listQuestions.size();
}

public class MyHealthViewHolder extends RecyclerView.ViewHolder{

    CardView cvParent;
    TextView tvQuestion;
    CheckBox cbYes, cbNo;

    public MyHealthViewHolder(View itemView) {
        super(itemView);
        cvParent = itemView.findViewById(R.id.card_view_my_health_status_rv);
        tvQuestion = itemView.findViewById(R.id.tv_eligibility_question_my_info);
        cbYes = itemView.findViewById(R.id.checkBoxYes_my_health_info);
        cbNo = itemView.findViewById(R.id.checkBoxNo_my_health_info);

    }
}
}
</code>```

Fragment:

```<code>public class DonorHealthStatus extends Fragment {

private static final int MY_SOCKET_TIMEOUT_MS = 100000;
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private DonorHealthStatusAdapter donorHealthStatusAdapter;
private ArrayList<DonorHealthStatusQuestionare> donorHealthStatusQuestionares = new ArrayList<>();
private HealthStatusCheck statusCheck = new HealthStatusCheck();
private String donorID;
private Donor donor;
private boolean checked;

public DonorHealthStatus() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_donor_health_status, container, false);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    donor = ((DisplayDonorDetails)getActivity()).getDonor();
    donorID = donor.getUserID();

    getHealthStatus(new HealthStatusCallBack() {
        @Override
        public void onSuccess(HealthStatusCheck healthStatusCheck) {
            statusCheck = healthStatusCheck;
            setHealthStatusView();
        }

        @Override
        public void onFail(String msg) {}
    });

}

// SETTING HEALTH STATUS POJO CLASS FROM DATABASE.
private void getHealthStatus(final HealthStatusCallBack healthStatusCallBack) {
    Utility.checkNetworkConnectionBoolean(getActivity());

    if(Utility.isNetworkEnabled){
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constants.GET_HEALTH_STATUS,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {

                            JSONArray jsonArray = new JSONArray(response);
                            JSONObject jsonObject = jsonArray.getJSONObject(0);
                            String code = jsonObject.getString("code");

                            if(code.equals("0001")){

                                statusCheck.setId(Integer.valueOf(jsonObject.getString("id")));
                                statusCheck.setDonorID(Integer.valueOf(jsonObject.getString("donorID")));

                                if(jsonObject.getString("q1").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q1").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q2").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q2").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q3").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q3").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q4").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q4").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q5").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q5").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q6").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q6").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q7").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q7").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q8").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q8").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q9").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q9").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q10").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q10").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q11").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q11").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q12").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q12").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q13").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q13").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q14").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q14").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q15").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q15").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q16").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q16").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q17").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q17").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q18").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q18").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q19").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q19").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q20").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q20").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }

                            }

                            healthStatusCallBack.onSuccess(statusCheck);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {}
                }
        ){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("donorID", donorID);
                return params;
            }
        };

        stringRequest.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        NetworkRequestSingleTon.getOurInstance(getActivity()).addToRequestQue(stringRequest);
    }else {
        Utility.checkNetworkConnectionAlert(getActivity());
    }

}

// SETTING RECYCLER VIEW OF QUESTIONARE FROM DATABASE.
private void setHealthStatusView() {

    recyclerView = getActivity().findViewById(R.id.rv_donor_health_info);
    layoutManager = new LinearLayoutManager(getActivity());

    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

    donorHealthStatusAdapter = new DonorHealthStatusAdapter(getActivity(),
            donorHealthStatusQuestionares, statusCheck);

    recyclerView.setAdapter(donorHealthStatusAdapter);

    Utility.checkGpsConnectionBoolean(getActivity());
    if(Utility.isNetworkEnabled){

        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constants.GET_HEALTH_QUESTIONARE,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {

                            JSONArray jsonArray = new JSONArray(response);

                            int count = 0;

                            while (count < jsonArray.length()){
                                JSONObject jsonObject = jsonArray.getJSONObject(count);

                                DonorHealthStatusQuestionare donorHealthStatusQuestionare =
                                        new DonorHealthStatusQuestionare();

                                donorHealthStatusQuestionare.setId(Integer.valueOf(jsonObject.getString("id")));
                                donorHealthStatusQuestionare.setQuestions(jsonObject.getString("questions"));

                                donorHealthStatusQuestionares.add(donorHealthStatusQuestionare);
                                count ++;

                            }

                            donorHealthStatusAdapter.notifyDataSetChanged();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }
        );
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        NetworkRequestSingleTon.getOurInstance(getActivity()).addToRequestQue(stringRequest);

    }else {
        Utility.checkNetworkConnectionAlert(getActivity());
    }

}

// CALL BACK INTERFACE TO GET POJO CLASS FROM VOLLEY BACKGROUND ACTIVITY.
public interface HealthStatusCallBack{

    void onSuccess(HealthStatusCheck healthStatusCheck);

    void onFail(String msg);
}
}
</code>```

LAYOUT XML:

```<code><android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view_health_status_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:orientation="horizontal"
    android:padding="12dp">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_eligibility_question"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/health_status_radio_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0">

        <CheckBox
            android:id="@+id/checkBoxYes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:text="@string/yes" />

        <CheckBox
            android:layout_toRightOf="@+id/checkBoxYes"
            android:layout_toEndOf="@+id/checkBoxYes"
            android:id="@+id/checkBoxNo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/no" />

    </RelativeLayout>

</LinearLayout>
</code>```

Result Check POJO Class:

```<code>public class HealthStatusCheck {
private int id;
private int donorID;
private boolean q1;
private boolean q2;
private boolean q3;
private boolean q4;
private boolean q5;
private boolean q6;
private boolean q7;
private boolean q8;
private boolean q9;
private boolean q10;
private boolean q11;
private boolean q12;
private boolean q13;
private boolean q14;
private boolean q15;
private boolean q16;
private boolean q17;
private boolean q18;
private boolean q19;
private boolean q20;

public HealthStatusCheck() {}

public HealthStatusCheck(int id, int donorID, boolean q1, boolean q2, boolean q3, boolean q4, boolean q5, boolean q6,
                         boolean q7, boolean q8, boolean q9, boolean q10, boolean q11, boolean q12, boolean q13,
                         boolean q14, boolean q15, boolean q16, boolean q17, boolean q18, boolean q19, boolean q20) {
    this.id = id;
    this.donorID = donorID;
    this.q1 = q1;
    this.q2 = q2;
    this.q3 = q3;
    this.q4 = q4;
    this.q5 = q5;
    this.q6 = q6;
    this.q7 = q7;
    this.q8 = q8;
    this.q9 = q9;
    this.q10 = q10;
    this.q11 = q11;
    this.q12 = q12;
    this.q13 = q13;
    this.q14 = q14;
    this.q15 = q15;
    this.q16 = q16;
    this.q17 = q17;
    this.q18 = q18;
    this.q19 = q19;
    this.q20 = q20;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getDonorID() {
    return donorID;
}

public void setDonorID(int donorID) {
    this.donorID = donorID;
}

public boolean isQ1() {
    return q1;
}

public void setQ1(boolean q1) {
    this.q1 = q1;
}

public boolean isQ2() {
    return q2;
}

public void setQ2(boolean q2) {
    this.q2 = q2;
}

public boolean isQ3() {
    return q3;
}

public void setQ3(boolean q3) {
    this.q3 = q3;
}

public boolean isQ4() {
    return q4;
}

public void setQ4(boolean q4) {
    this.q4 = q4;
}

public boolean isQ5() {
    return q5;
}

public void setQ5(boolean q5) {
    this.q5 = q5;
}

public boolean isQ6() {
    return q6;
}

public void setQ6(boolean q6) {
    this.q6 = q6;
}

public boolean isQ7() {
    return q7;
}

public void setQ7(boolean q7) {
    this.q7 = q7;
}

public boolean isQ8() {
    return q8;
}

public void setQ8(boolean q8) {
    this.q8 = q8;
}

public boolean isQ9() {
    return q9;
}

public void setQ9(boolean q9) {
    this.q9 = q9;
}

public boolean isQ10() {
    return q10;
}

public void setQ10(boolean q10) {
    this.q10 = q10;
}

public boolean isQ11() {
    return q11;
}

public void setQ11(boolean q11) {
    this.q11 = q11;
}

public boolean isQ12() {
    return q12;
}

public void setQ12(boolean q12) {
    this.q12 = q12;
}

public boolean isQ13() {
    return q13;
}

public void setQ13(boolean q13) {
    this.q13 = q13;
}

public boolean isQ14() {
    return q14;
}

public void setQ14(boolean q14) {
    this.q14 = q14;
}

public boolean isQ15() {
    return q15;
}

public void setQ15(boolean q15) {
    this.q15 = q15;
}

public boolean isQ16() {
    return q16;
}

public void setQ16(boolean q16) {
    this.q16 = q16;
}

public boolean isQ17() {
    return q17;
}

public void setQ17(boolean q17) {
    this.q17 = q17;
}

public boolean isQ18() {
    return q18;
}

public void setQ18(boolean q18) {
    this.q18 = q18;
}

public boolean isQ19() {
    return q19;
}

public void setQ19(boolean q19) {
    this.q19 = q19;
}

public boolean isQ20() {
    return q20;
}

public void setQ20(boolean q20) {
    this.q20 = q20;
}
}
</code>```

Questions POJO class:

```<code>public class DonorHealthStatusQuestionare {
private int id;
private String questions;
boolean isSelected;

public DonorHealthStatusQuestionare() {}

public DonorHealthStatusQuestionare(int id, String questions) {
    this.id = id;
    this.questions = questions;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getQuestions() {
    return questions;
}

public void setQuestions(String questions) {
    this.questions = questions;
}

public boolean isSelected() {
    return isSelected;
}

public void setSelected(boolean selected) {
    isSelected = selected;
}
}
</code>```

答:
For showing recyleview with checkbox from POJO class here is the complete solution of this.

POJO class:

```<code>import java.io.Serializable;

public class Student implements Serializable {

private static final long serialVersionUID = 1L;
private String name;
private String emailId;
private boolean isSelected;

public Student() {

}

public Student(String name, String emailId) {

 this.name = name;
 this.emailId = emailId;

}

public Student(String name, String emailId, boolean isSelected) {

this.name = name;
this.emailId = emailId;
this.isSelected = isSelected;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmailId() {
return emailId;
}

public void setEmailId(String emailId) {
this.emailId = emailId;
}

public boolean isSelected() {
return isSelected;
}

public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
 }

}
</code>```

Activity:

```<code>import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class CardViewActivity extends AppCompatActivity {

 private Toolbar toolbar;
 private RecyclerView mRecyclerView;
 private RecyclerView.Adapter mAdapter;
 private RecyclerView.LayoutManager mLayoutManager;
 private List<Student> studentList;
 private Button btnSelection;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  toolbar = (Toolbar) findViewById(R.id.toolbar);
  btnSelection = (Button) findViewById(R.id.btnShow);
  studentList = new ArrayList<Student>();

  for (int i = 1; i <= 15; i++) {
   Student st = new Student("Student " + i, "androidstudent" + i
     + "@gmail.com", false);

   studentList.add(st);
  }

  if (toolbar != null) {
   setSupportActionBar(toolbar);
   getSupportActionBar().setTitle("Android Students");

  }
  mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
  mRecyclerView.setHasFixedSize(true);
  mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  mAdapter = new CardViewDataAdapter(studentList);
  mRecyclerView.setAdapter(mAdapter);

  btnSelection.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    String data = "";
    List<Student> stList = ((CardViewDataAdapter) mAdapter)
      .getStudentist();

    for (int i = 0; i < stList.size(); i++) {
     Student singleStudent = stList.get(i);
     if (singleStudent.isSelected() == true) {
      data = data + "\n" + singleStudent.getName().toString();
     }
    }
   }});
 }
}
</code>```

Activity XML :

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:scrollbars="vertical" />

    <Button
        android:id="@+id/btnShow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="Show Selected"
        android:background="#00796B"
        android:textColor="@color/TextPrimaryColor"/>

</LinearLayout>
</code>```

Card Adapter:

```<code>import java.util.List;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class CardViewDataAdapter extends
  RecyclerView.Adapter<CardViewDataAdapter.ViewHolder> {
 private List<Student> stList;
 public CardViewDataAdapter(List<Student> students) {
  this.stList = students;

 }

 @Override
 public CardViewDataAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
   int viewType) {
  View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
    R.layout.cardview_row, null);
  ViewHolder viewHolder = new ViewHolder(itemLayoutView);
  return viewHolder;
 }

 @Override
 public void onBindViewHolder(ViewHolder viewHolder, int position) {

  final int pos = position;
  viewHolder.tvName.setText(stList.get(position).getName());
  viewHolder.tvEmailId.setText(stList.get(position).getEmailId());
  viewHolder.chkSelected.setChecked(stList.get(position).isSelected());
  viewHolder.chkSelected.setTag(stList.get(position));

  viewHolder.chkSelected.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
    CheckBox cb = (CheckBox) v;
    Student contact = (Student) cb.getTag();
    contact.setSelected(cb.isChecked());
    stList.get(pos).setSelected(cb.isChecked());
   }
  });
 }
 // Return the size arraylist
 @Override
 public int getItemCount() {
  return stList.size();
 }

 public static class ViewHolder extends RecyclerView.ViewHolder {

  public TextView tvName;
  public TextView tvEmailId;
  public CheckBox chkSelected;
  public Student singlestudent;

  public ViewHolder(View itemLayoutView) {
   super(itemLayoutView);
   tvName = (TextView) itemLayoutView.findViewById(R.id.tvName);
   tvEmailId = (TextView) itemLayoutView.findViewById(R.id.tvEmailId);
   chkSelected = (CheckBox) itemLayoutView.findViewById(R.id.chkSelected);
  }
 }
 public List<Student> getStudentist() {
  return stList;
 }

}
</code>```

Card row:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    card_view:cardCornerRadius="5dp"

    card_view:cardUseCompatPadding="true" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" >

        <TextView
            android:id="@+id/tvName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="name"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/tvEmailId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvName"
            android:text="email"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

        <CheckBox
            android:id="@+id/chkSelected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            />
    </RelativeLayout>

</android.support.v7.widget.CardView>
</code>```

Happy coding!!

Body:
Let me tell you what exactly I needed. I need to load 20 questions from my MySql DB to recyclerview. Questions are saved in a table that has two columns ie, id and question. I can successfully load these questions to my recyclerview with the help of an adapter. Here is the twist, I need to mark these questions as "Yes" or "No" in my recyclerview by using checkboxes for each based on what exactly logged in user answered before this questions from his profile. Also, I expect good database and object class design solution in order to achieve this.

Here what I have tried,

Adapter Class:

public class MyHealthInfoAdapter extends RecyclerView.Adapter<MyHealthInfoAdapter.MyHealthViewHolder> {

private Context context;
private ArrayList<DonorHealthStatusQuestionare> listQuestions;

public MyHealthInfoAdapter(Context context, ArrayList<DonorHealthStatusQuestionare> listQuestions) {
    this.context = context;
    this.listQuestions = listQuestions;
}

@Override
public MyHealthViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_my_health_info, parent, false);
    return new MyHealthViewHolder(view);
}

@Override
public void onBindViewHolder(final MyHealthViewHolder holder, int position) {

    DonorHealthStatusQuestionare donorHealthStatusQuestionare = listQuestions.get(position);
    holder.tvQuestion.setText(donorHealthStatusQuestionare.getQuestions());

}

@Override
public int getItemCount() {
    return listQuestions.size();
}

public class MyHealthViewHolder extends RecyclerView.ViewHolder{

    CardView cvParent;
    TextView tvQuestion;
    CheckBox cbYes, cbNo;

    public MyHealthViewHolder(View itemView) {
        super(itemView);
        cvParent = itemView.findViewById(R.id.card_view_my_health_status_rv);
        tvQuestion = itemView.findViewById(R.id.tv_eligibility_question_my_info);
        cbYes = itemView.findViewById(R.id.checkBoxYes_my_health_info);
        cbNo = itemView.findViewById(R.id.checkBoxNo_my_health_info);

    }
}
}

Fragment:

public class DonorHealthStatus extends Fragment {

private static final int MY_SOCKET_TIMEOUT_MS = 100000;
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private DonorHealthStatusAdapter donorHealthStatusAdapter;
private ArrayList<DonorHealthStatusQuestionare> donorHealthStatusQuestionares = new ArrayList<>();
private HealthStatusCheck statusCheck = new HealthStatusCheck();
private String donorID;
private Donor donor;
private boolean checked;

public DonorHealthStatus() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_donor_health_status, container, false);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    donor = ((DisplayDonorDetails)getActivity()).getDonor();
    donorID = donor.getUserID();

    getHealthStatus(new HealthStatusCallBack() {
        @Override
        public void onSuccess(HealthStatusCheck healthStatusCheck) {
            statusCheck = healthStatusCheck;
            setHealthStatusView();
        }

        @Override
        public void onFail(String msg) {}
    });

}

// SETTING HEALTH STATUS POJO CLASS FROM DATABASE.
private void getHealthStatus(final HealthStatusCallBack healthStatusCallBack) {
    Utility.checkNetworkConnectionBoolean(getActivity());

    if(Utility.isNetworkEnabled){
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constants.GET_HEALTH_STATUS,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {

                            JSONArray jsonArray = new JSONArray(response);
                            JSONObject jsonObject = jsonArray.getJSONObject(0);
                            String code = jsonObject.getString("code");

                            if(code.equals("0001")){

                                statusCheck.setId(Integer.valueOf(jsonObject.getString("id")));
                                statusCheck.setDonorID(Integer.valueOf(jsonObject.getString("donorID")));

                                if(jsonObject.getString("q1").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q1").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q2").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q2").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q3").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q3").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q4").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q4").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q5").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q5").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q6").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q6").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q7").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q7").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q8").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q8").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q9").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q9").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q10").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q10").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q11").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q11").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q12").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q12").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q13").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q13").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q14").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q14").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q15").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q15").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q16").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q16").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q17").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q17").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q18").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q18").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q19").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q19").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q20").equals("0")){
                                    checked = false;
                                    statusCheck.setQ1(checked);
                                }else if(jsonObject.getString("q20").equals("1")){
                                    checked = true;
                                    statusCheck.setQ1(checked);
                                }

                            }

                            healthStatusCallBack.onSuccess(statusCheck);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {}
                }
        ){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("donorID", donorID);
                return params;
            }
        };

        stringRequest.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        NetworkRequestSingleTon.getOurInstance(getActivity()).addToRequestQue(stringRequest);
    }else {
        Utility.checkNetworkConnectionAlert(getActivity());
    }

}

// SETTING RECYCLER VIEW OF QUESTIONARE FROM DATABASE.
private void setHealthStatusView() {

    recyclerView = getActivity().findViewById(R.id.rv_donor_health_info);
    layoutManager = new LinearLayoutManager(getActivity());

    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

    donorHealthStatusAdapter = new DonorHealthStatusAdapter(getActivity(),
            donorHealthStatusQuestionares, statusCheck);

    recyclerView.setAdapter(donorHealthStatusAdapter);

    Utility.checkGpsConnectionBoolean(getActivity());
    if(Utility.isNetworkEnabled){

        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constants.GET_HEALTH_QUESTIONARE,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {

                            JSONArray jsonArray = new JSONArray(response);

                            int count = 0;

                            while (count < jsonArray.length()){
                                JSONObject jsonObject = jsonArray.getJSONObject(count);

                                DonorHealthStatusQuestionare donorHealthStatusQuestionare =
                                        new DonorHealthStatusQuestionare();

                                donorHealthStatusQuestionare.setId(Integer.valueOf(jsonObject.getString("id")));
                                donorHealthStatusQuestionare.setQuestions(jsonObject.getString("questions"));

                                donorHealthStatusQuestionares.add(donorHealthStatusQuestionare);
                                count ++;

                            }

                            donorHealthStatusAdapter.notifyDataSetChanged();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }
        );
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        NetworkRequestSingleTon.getOurInstance(getActivity()).addToRequestQue(stringRequest);

    }else {
        Utility.checkNetworkConnectionAlert(getActivity());
    }

}

// CALL BACK INTERFACE TO GET POJO CLASS FROM VOLLEY BACKGROUND ACTIVITY.
public interface HealthStatusCallBack{

    void onSuccess(HealthStatusCheck healthStatusCheck);

    void onFail(String msg);
}
}

LAYOUT XML:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view_health_status_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:orientation="horizontal"
    android:padding="12dp">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_eligibility_question"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/health_status_radio_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0">

        <CheckBox
            android:id="@+id/checkBoxYes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:text="@string/yes" />

        <CheckBox
            android:layout_toRightOf="@+id/checkBoxYes"
            android:layout_toEndOf="@+id/checkBoxYes"
            android:id="@+id/checkBoxNo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/no" />

    </RelativeLayout>

</LinearLayout>

Result Check POJO Class:

public class HealthStatusCheck {
private int id;
private int donorID;
private boolean q1;
private boolean q2;
private boolean q3;
private boolean q4;
private boolean q5;
private boolean q6;
private boolean q7;
private boolean q8;
private boolean q9;
private boolean q10;
private boolean q11;
private boolean q12;
private boolean q13;
private boolean q14;
private boolean q15;
private boolean q16;
private boolean q17;
private boolean q18;
private boolean q19;
private boolean q20;

public HealthStatusCheck() {}

public HealthStatusCheck(int id, int donorID, boolean q1, boolean q2, boolean q3, boolean q4, boolean q5, boolean q6,
                         boolean q7, boolean q8, boolean q9, boolean q10, boolean q11, boolean q12, boolean q13,
                         boolean q14, boolean q15, boolean q16, boolean q17, boolean q18, boolean q19, boolean q20) {
    this.id = id;
    this.donorID = donorID;
    this.q1 = q1;
    this.q2 = q2;
    this.q3 = q3;
    this.q4 = q4;
    this.q5 = q5;
    this.q6 = q6;
    this.q7 = q7;
    this.q8 = q8;
    this.q9 = q9;
    this.q10 = q10;
    this.q11 = q11;
    this.q12 = q12;
    this.q13 = q13;
    this.q14 = q14;
    this.q15 = q15;
    this.q16 = q16;
    this.q17 = q17;
    this.q18 = q18;
    this.q19 = q19;
    this.q20 = q20;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getDonorID() {
    return donorID;
}

public void setDonorID(int donorID) {
    this.donorID = donorID;
}

public boolean isQ1() {
    return q1;
}

public void setQ1(boolean q1) {
    this.q1 = q1;
}

public boolean isQ2() {
    return q2;
}

public void setQ2(boolean q2) {
    this.q2 = q2;
}

public boolean isQ3() {
    return q3;
}

public void setQ3(boolean q3) {
    this.q3 = q3;
}

public boolean isQ4() {
    return q4;
}

public void setQ4(boolean q4) {
    this.q4 = q4;
}

public boolean isQ5() {
    return q5;
}

public void setQ5(boolean q5) {
    this.q5 = q5;
}

public boolean isQ6() {
    return q6;
}

public void setQ6(boolean q6) {
    this.q6 = q6;
}

public boolean isQ7() {
    return q7;
}

public void setQ7(boolean q7) {
    this.q7 = q7;
}

public boolean isQ8() {
    return q8;
}

public void setQ8(boolean q8) {
    this.q8 = q8;
}

public boolean isQ9() {
    return q9;
}

public void setQ9(boolean q9) {
    this.q9 = q9;
}

public boolean isQ10() {
    return q10;
}

public void setQ10(boolean q10) {
    this.q10 = q10;
}

public boolean isQ11() {
    return q11;
}

public void setQ11(boolean q11) {
    this.q11 = q11;
}

public boolean isQ12() {
    return q12;
}

public void setQ12(boolean q12) {
    this.q12 = q12;
}

public boolean isQ13() {
    return q13;
}

public void setQ13(boolean q13) {
    this.q13 = q13;
}

public boolean isQ14() {
    return q14;
}

public void setQ14(boolean q14) {
    this.q14 = q14;
}

public boolean isQ15() {
    return q15;
}

public void setQ15(boolean q15) {
    this.q15 = q15;
}

public boolean isQ16() {
    return q16;
}

public void setQ16(boolean q16) {
    this.q16 = q16;
}

public boolean isQ17() {
    return q17;
}

public void setQ17(boolean q17) {
    this.q17 = q17;
}

public boolean isQ18() {
    return q18;
}

public void setQ18(boolean q18) {
    this.q18 = q18;
}

public boolean isQ19() {
    return q19;
}

public void setQ19(boolean q19) {
    this.q19 = q19;
}

public boolean isQ20() {
    return q20;
}

public void setQ20(boolean q20) {
    this.q20 = q20;
}
}

Questions POJO class:

public class DonorHealthStatusQuestionare {
private int id;
private String questions;
boolean isSelected;

public DonorHealthStatusQuestionare() {}

public DonorHealthStatusQuestionare(int id, String questions) {
    this.id = id;
    this.questions = questions;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getQuestions() {
    return questions;
}

public void setQuestions(String questions) {
    this.questions = questions;
}

public boolean isSelected() {
    return isSelected;
}

public void setSelected(boolean selected) {
    isSelected = selected;
}
}

Body:
For showing recyleview with checkbox from POJO class here is the complete solution of this.

POJO class:

import java.io.Serializable;

public class Student implements Serializable {

private static final long serialVersionUID = 1L;
private String name;
private String emailId;
private boolean isSelected;

public Student() {

}

public Student(String name, String emailId) {

 this.name = name;
 this.emailId = emailId;

}

public Student(String name, String emailId, boolean isSelected) {

this.name = name;
this.emailId = emailId;
this.isSelected = isSelected;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmailId() {
return emailId;
}

public void setEmailId(String emailId) {
this.emailId = emailId;
}

public boolean isSelected() {
return isSelected;
}

public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
 }

}

Activity:

import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class CardViewActivity extends AppCompatActivity {

 private Toolbar toolbar;
 private RecyclerView mRecyclerView;
 private RecyclerView.Adapter mAdapter;
 private RecyclerView.LayoutManager mLayoutManager;
 private List<Student> studentList;
 private Button btnSelection;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  toolbar = (Toolbar) findViewById(R.id.toolbar);
  btnSelection = (Button) findViewById(R.id.btnShow);
  studentList = new ArrayList<Student>();

  for (int i = 1; i <= 15; i++) {
   Student st = new Student("Student " + i, "androidstudent" + i
     + "@gmail.com", false);

   studentList.add(st);
  }

  if (toolbar != null) {
   setSupportActionBar(toolbar);
   getSupportActionBar().setTitle("Android Students");

  }
  mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
  mRecyclerView.setHasFixedSize(true);
  mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  mAdapter = new CardViewDataAdapter(studentList);
  mRecyclerView.setAdapter(mAdapter);

  btnSelection.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    String data = "";
    List<Student> stList = ((CardViewDataAdapter) mAdapter)
      .getStudentist();

    for (int i = 0; i < stList.size(); i++) {
     Student singleStudent = stList.get(i);
     if (singleStudent.isSelected() == true) {
      data = data + "\n" + singleStudent.getName().toString();
     }
    }
   }});
 }
}

Activity XML :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:scrollbars="vertical" />

    <Button
        android:id="@+id/btnShow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="Show Selected"
        android:background="#00796B"
        android:textColor="@color/TextPrimaryColor"/>

</LinearLayout>

Card Adapter:

import java.util.List;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class CardViewDataAdapter extends
  RecyclerView.Adapter<CardViewDataAdapter.ViewHolder> {
 private List<Student> stList;
 public CardViewDataAdapter(List<Student> students) {
  this.stList = students;

 }

 @Override
 public CardViewDataAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
   int viewType) {
  View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
    R.layout.cardview_row, null);
  ViewHolder viewHolder = new ViewHolder(itemLayoutView);
  return viewHolder;
 }

 @Override
 public void onBindViewHolder(ViewHolder viewHolder, int position) {

  final int pos = position;
  viewHolder.tvName.setText(stList.get(position).getName());
  viewHolder.tvEmailId.setText(stList.get(position).getEmailId());
  viewHolder.chkSelected.setChecked(stList.get(position).isSelected());
  viewHolder.chkSelected.setTag(stList.get(position));

  viewHolder.chkSelected.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
    CheckBox cb = (CheckBox) v;
    Student contact = (Student) cb.getTag();
    contact.setSelected(cb.isChecked());
    stList.get(pos).setSelected(cb.isChecked());
   }
  });
 }
 // Return the size arraylist
 @Override
 public int getItemCount() {
  return stList.size();
 }

 public static class ViewHolder extends RecyclerView.ViewHolder {

  public TextView tvName;
  public TextView tvEmailId;
  public CheckBox chkSelected;
  public Student singlestudent;

  public ViewHolder(View itemLayoutView) {
   super(itemLayoutView);
   tvName = (TextView) itemLayoutView.findViewById(R.id.tvName);
   tvEmailId = (TextView) itemLayoutView.findViewById(R.id.tvEmailId);
   chkSelected = (CheckBox) itemLayoutView.findViewById(R.id.chkSelected);
  }
 }
 public List<Student> getStudentist() {
  return stList;
 }

}

Card row:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    card_view:cardCornerRadius="5dp"

    card_view:cardUseCompatPadding="true" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" >

        <TextView
            android:id="@+id/tvName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="name"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/tvEmailId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvName"
            android:text="email"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

        <CheckBox
            android:id="@+id/chkSelected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            />
    </RelativeLayout>

</android.support.v7.widget.CardView>

Happy coding!!


来源: stackexchange

问:
Downsides of using Makefile rules for deployment?
I have an open-source project where I'm using Make for things like tests and static checks. The deployment process is approximately this:

```<code>make html
rsync static_pages my_domain.com:static_pages
ssh my_domain.com "cp -r static_pages /var/www/webroot"
</code>```

Is there a reason not to have this deployment process publicly in the Makefile? Does Make have gotchas that make it unsuitable for deployment? Is there a security issue revealing server names or directory structure? Or something else that I haven't though of?

答:
As long as this does the job, it is OK. You worry about privacy of some rules, but why is your make script more vulnerable to alien curiosity than any other process on your build or deployment  workstation? If this is because make script is published as open source, the easy workaround could be to keep sensitive names as environment variables, e.g.</p>

```<code>html:
    rsync static_pages $(DOMAIN):static_pages
    ssh $(DOMAIN) "cp -r static_pages $(WEBROOT)"
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have an open-source project where I'm using Make for things like tests and static checks. The deployment process is approximately this:

make html
rsync static_pages my_domain.com:static_pages
ssh my_domain.com "cp -r static_pages /var/www/webroot"

Is there a reason not to have this deployment process publicly in the Makefile? Does Make have gotchas that make it unsuitable for deployment? Is there a security issue revealing server names or directory structure? Or something else that I haven't though of?

Body:
As long as this does the job, it is OK. You worry about privacy of some rules, but why is your make script more vulnerable to alien curiosity than any other process on your build or deployment  workstation? If this is because make script is published as open source, the easy workaround could be to keep sensitive names as environment variables, e.g.

html:
    rsync static_pages $(DOMAIN):static_pages
    ssh $(DOMAIN) "cp -r static_pages $(WEBROOT)"


问:
How to make a dataframe of windows?
Suppose I have a pandas series:

```<code>0 x[0]
1 x[1]
...
n x[n]
...
</code>```

and I want to create a pandas.Dataframe whose rows are the windows of size k in the dataframe. So, for k=2, we have

```<code>  1     0
0 x[0]  x[1]
1 x[1]  x[2]
2 x[2]  x[3]
...
n-1 x[n-1] x[n]
</code>```

There are some obvious clunky ways of doing it, but it seems like there should be a one-line way.

答:
Not ideal, but likely better than a raw for loop would be:

Code:

```<code>def shift_to_columns(vector, k):
    return pd.DataFrame({i: vector.slice_shift(-i)[:len(vector)-k+1]
                         for i in range(k)})
</code>```

Test Code:

```<code>import pandas as pd
data = pd.Series(range(10))
print(data)
print(shift_to_columns(data, 3))
</code>```

Results:

```<code>0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9

dtype: int64
   0  1  2
0  0  1  2
1  1  2  3
2  2  3  4
3  3  4  5
4  4  5  6
5  5  6  7
6  6  7  8
7  7  8  9
</code>```

Title: How to make a dataframe of windows?

Body:
Suppose I have a pandas series:

0 x[0]
1 x[1]
...
n x[n]
...

and I want to create a pandas.Dataframe whose rows are the windows of size k in the dataframe. So, for k=2, we have

  1     0
0 x[0]  x[1]
1 x[1]  x[2]
2 x[2]  x[3]
...
n-1 x[n-1] x[n]

There are some obvious clunky ways of doing it, but it seems like there should be a one-line way.

Body:
Not ideal, but likely better than a raw for loop would be:

Code:

def shift_to_columns(vector, k):
    return pd.DataFrame({i: vector.slice_shift(-i)[:len(vector)-k+1]
                         for i in range(k)})

Test Code:

import pandas as pd
data = pd.Series(range(10))
print(data)
print(shift_to_columns(data, 3))

Results:

0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9

dtype: int64
   0  1  2
0  0  1  2
1  1  2  3
2  2  3  4
3  3  4  5
4  4  5  6
5  5  6  7
6  6  7  8
7  7  8  9


问:
iOS app can't find with search in app store but can found with link form iTune with app id
I have problem about my app.

I can't find app with search in app store even am search with full name of app. At first I think app is not appear in app store because is delay but I can find and download the app in app store with open link form menu "View on App Store" in iTuneConnect.

How I can fix this or I should to contact apple.

EDIT
Finally my app is show in app store with search.
Solution is just contact the apple.

答:
I have faced a similar issue a while ago. Something happens with search engine. I found a tricky workaround and it worked for me. Idea is to change any app metadata and save it and revert it back after and save it. And app was available with in hours after that.

I did the following.

Removed the Privacy Policy, save it and reverted it back and save it.
iTunesConnect -> YOUR_APP -> App Information

Removed 1 available territories (countries), save it and then added it back and save it.
iTunesConnect -> YOUR_APP -> Pricing & Availability -> Availability

It worked for me Hopefully it will work for you.


问:
How to remove brackets in the email claim from Azure AD B2C
I am trying to remove the brackets in the email claims that I getfrom Azure AD B2C.

After the user logs in I decode user's token and get the email from that. But the email that I get has brackets in it. The email looks like this ["email@email.com"] which its make it ugly when I save it to the database.

Is there some setting to remove the brackets from the email claim?

```<code>JObject ParseIdToken(string idToken)
{
    // Get the piece with actual user info
    idToken = idToken.Split('.')[1];
    idToken = Base64UrlDecode(idToken);
    return JObject.Parse(idToken);
}

private string Base64UrlDecode(string s)
{
    s = s.Replace('-', '+').Replace('_', '/');
    s = s.PadRight(s.Length + (4 - s.Length % 4) % 4, '=');
    var byteArray = Convert.FromBase64String(s);
    var decoded = Encoding.UTF8.GetString(byteArray, 0, byteArray.Count());
    return decoded;
}

public  void CacheUser(AuthenticationResult ar)
{
    JObject user = ParseIdToken(ar.IdToken);
    var cache = new CachedUsers
    {
        FullName = user["name"]?.ToString(),
        Email = user["emails"]?.ToString()

    };
     BlobCache.LocalMachine.InsertObject("usercached", cache);
}
</code>```

That is my code to get the email. Why does the email have brackets? I guess the problem is not in my code but maybe there is some setting in Azure AD B2C that makes it like that because when I try to decode the token from https://jwt.io/ it returns the same, the email with brackets. Has anyone experienced this?

Here is the payload from jwt.io

You can see the difference between name and the email. The email has brackets like this [ ] and what I want to know is how to remove those brackets and make it like name. Because when I get the email in Xamarin forms it has those brackets too so instead of emailname@gmail.com  it get like this ["emailname@gmail.com"]

答:
In JSON, brackets denote arrays. See this basic JSON Arrays documentation.

While not easily exposed via the Azure AD B2C UI, it's technically possible for a user to have multiple emails linked to their account, which is why the email claim is an array.

The reason the string you are seeing is shown as ["user@email.com"] is because you are calling .ToString() on a JSON array. You need to modify your code to obtain a specific element of that array, for example, the first element:

public  void CacheUser(AuthenticationResult ar)
{
    JObject user = ParseIdToken(ar.IdToken);
    var cache = new CachedUsers
    {
        FullName = user["name"]?.ToString(),
        Email = user["emails"]?.FirstOrDefault()?.ToString()
    };
     BlobCache.LocalMachine.InsertObject("usercached", cache);
}
```

Body:
I am trying to remove the brackets in the email claims that I getfrom Azure AD B2C.

After the user logs in I decode user's token and get the email from that. But the email that I get has brackets in it. The email looks like this ["email@email.com"] which its make it ugly when I save it to the database.

Is there some setting to remove the brackets from the email claim?

JObject ParseIdToken(string idToken)
{
    // Get the piece with actual user info
    idToken = idToken.Split('.')[1];
    idToken = Base64UrlDecode(idToken);
    return JObject.Parse(idToken);
}

private string Base64UrlDecode(string s)
{
    s = s.Replace('-', '+').Replace('_', '/');
    s = s.PadRight(s.Length + (4 - s.Length % 4) % 4, '=');
    var byteArray = Convert.FromBase64String(s);
    var decoded = Encoding.UTF8.GetString(byteArray, 0, byteArray.Count());
    return decoded;
}

public  void CacheUser(AuthenticationResult ar)
{
    JObject user = ParseIdToken(ar.IdToken);
    var cache = new CachedUsers
    {
        FullName = user["name"]?.ToString(),
        Email = user["emails"]?.ToString()

    };
     BlobCache.LocalMachine.InsertObject("usercached", cache);
}

That is my code to get the email. Why does the email have brackets? I guess the problem is not in my code but maybe there is some setting in Azure AD B2C that makes it like that because when I try to decode the token from https://jwt.io/ it returns the same, the email with brackets. Has anyone experienced this?

Here is the payload from jwt.io

You can see the difference between name and the email. The email has brackets like this [ ] and what I want to know is how to remove those brackets and make it like name. Because when I get the email in Xamarin forms it has those brackets too so instead of emailname@gmail.com  it get like this ["emailname@gmail.com"]


问:
Caused by: java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64 OpenTok Tokbox
I'm developing video conference app, so i need to create a independent rooms for users for conference. so i'm using opentok (tokbox) sdk for android. below are my gradle compile files for opentok :

```<code>compile 'com.opentok.android:opentok-android-sdk:2.12.0'
compile 'com.tokbox:opentok-server-sdk:2.3.2'
</code>```

Now i am genereate session id and token id with the help of opentok server sdk (java). this is the code for generating session id and token id.

```<code>//java code
OpenTok openTok = new OpenTok(Integer.parseInt(OpenTokConfig.API_KEY), OpenTokConfig.SECRET_KEY);
try {
     SessionProperties sessionProperties = new SessionProperties.Builder().mediaMode(MediaMode.ROUTED).build();
     Session session = openTok.createSession(sessionProperties);
     sessionId = session.getSessionId();
     //successfully we got the session id here
     tokenId = openTok.generateToken(sessionId); //app crashed here
} catch (OpenTokException e) {
     e.printStackTrace();
}
</code>```

After debugging this code, we got the session id successfully, but i have facing the problem in generating tokenid.App is crashed suddenly at this point, it returns

```<code>`Caused by: java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64
at com.opentok.util.Crypto.decodeSessionId(Crypto.java:47)
at com.opentok.OpenTok.generateToken(OpenTok.java:131)
at com.opentok.OpenTok.generateToken(OpenTok.java:181)`
</code>```

I had going in depth debugging into opentok sdk the app crashed in this method

```<code>//class name is : Crypto
public static List<String> decodeSessionId(String sessionId) throws UnsupportedEncodingException {
    sessionId = sessionId.substring(2);
    sessionId = sessionId.replaceAll("-", "+").replaceAll("_", "/");
    byte[] buffer = Base64.decodeBase64(sessionId); //app crashed in this line
    sessionId = new String(buffer, "UTF-8");
    return new ArrayList<String>(Arrays.asList(sessionId.split("~")));
}
</code>```

I know the problem is related to decode issue.I had searched about this issue in so many places, but i had not getting any related answers about this issue.Opentok team simply says upgrade your sdk's. Please give the right direction.

答:
This is the same as this problem Apache Commons Codec with Android: could not find method

The OpenTok Java SDK is meant to be used in a Server-Side application, not in your Android application because otherwise you compromise your API Secret. Someone could take it and use it to create their own OpenTok Sessions and you get the bill. The recommended way to do this is to have a server-side API that you call from your Android application to fetch a sessionId and token.

If you still want to get this to work in your Android app you might be able to include commons-codec 1.4+ to get this method. Otherwise you might need to fork the OpenTok Java SDK and have it use an older version of the Base64.decodeBase64 method that takes a byte[] instead of a String.

Body:
I'm developing video conference app, so i need to create a independent rooms for users for conference. so i'm using opentok (tokbox) sdk for android. below are my gradle compile files for opentok :

compile 'com.opentok.android:opentok-android-sdk:2.12.0'
compile 'com.tokbox:opentok-server-sdk:2.3.2'

Now i am genereate session id and token id with the help of opentok server sdk (java). this is the code for generating session id and token id.

//java code
OpenTok openTok = new OpenTok(Integer.parseInt(OpenTokConfig.API_KEY), OpenTokConfig.SECRET_KEY);
try {
     SessionProperties sessionProperties = new SessionProperties.Builder().mediaMode(MediaMode.ROUTED).build();
     Session session = openTok.createSession(sessionProperties);
     sessionId = session.getSessionId();
     //successfully we got the session id here
     tokenId = openTok.generateToken(sessionId); //app crashed here
} catch (OpenTokException e) {
     e.printStackTrace();
}

After debugging this code, we got the session id successfully, but i have facing the problem in generating tokenid.App is crashed suddenly at this point, it returns

`Caused by: java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64
at com.opentok.util.Crypto.decodeSessionId(Crypto.java:47)
at com.opentok.OpenTok.generateToken(OpenTok.java:131)
at com.opentok.OpenTok.generateToken(OpenTok.java:181)`

I had going in depth debugging into opentok sdk the app crashed in this method

//class name is : Crypto
public static List<String> decodeSessionId(String sessionId) throws UnsupportedEncodingException {
    sessionId = sessionId.substring(2);
    sessionId = sessionId.replaceAll("-", "+").replaceAll("_", "/");
    byte[] buffer = Base64.decodeBase64(sessionId); //app crashed in this line
    sessionId = new String(buffer, "UTF-8");
    return new ArrayList<String>(Arrays.asList(sessionId.split("~")));
}

I know the problem is related to decode issue.I had searched about this issue in so many places, but i had not getting any related answers about this issue.Opentok team simply says upgrade your sdk's. Please give the right direction.


问:
setInterval loop not working
I am creating a simple image slide with JavaScript, but when I loop through all the images, I can not reset the loop:

```<code>var images = document.querySelectorAll(".slide-img");
var index = 0;
var time = 1000;

function reset(){
    for(var i = 0; i <= 3; i++){
        images[i].style.display = 'none';
        images[0].style.display = 'block';
    }
}

reset();

var looper = setInterval(function(){
    index++;
    images[index].style.display = 'block';

    if(index == 3){
        index = 0;
        images[index].style.display = 'block';
        //or calling reset() again.
    }

}, 1000);
</code>```

After setting all the image display:noneexcept the first one, I tried calling setInterval for looping all my images, but problem occurs when the index is 3. I am calling the reset() function and it is not working?

答:
Your code has a few problems.

The code inside the if statement doesn't reset all the images to hidden. So you would need to call reset function instead

Your reset function doesn't reset the index.

You should set index 0 to block once, and then loop through the rest instead of setting index 0 to block in each iteration.

Because you reset when index == 3, you will never see the last image. You should reset on the following iteration to ensure that each image is visible for one second.

See my example below.

var images = document.querySelectorAll(".slide-img");
var index = 0;
var time = 1000;

function reset(){
  index = 0;
  images[0].style.display = 'block';
  for(var i = 1; i < images.length; i++){
    images[i].style.display = 'none';
  }
}

reset();

setInterval(function(){
  index++;
  if(index >= images.length){
    reset();
  } else {
   images[index].style.display = 'block';
  }
}, 1000);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
  display: flex;
}

.slide-img {
  width: 100px;
  height: 100px;
}</code>```

```

If you have other question on why my code is different than yours, ask in the comments. But I think the code should be clear and understandable.

Title: setInterval loop not working

Body:
I am creating a simple image slide with JavaScript, but when I loop through all the images, I can not reset the loop:

var images = document.querySelectorAll(".slide-img");
var index = 0;
var time = 1000;

function reset(){
    for(var i = 0; i <= 3; i++){
        images[i].style.display = 'none';
        images[0].style.display = 'block';
    }
}

reset();

var looper = setInterval(function(){
    index++;
    images[index].style.display = 'block';

    if(index == 3){
        index = 0;
        images[index].style.display = 'block';
        //or calling reset() again.
    }

}, 1000);

After setting all the image display:noneexcept the first one, I tried calling setInterval for looping all my images, but problem occurs when the index is 3. I am calling the reset() function and it is not working?

Body:
Your code has a few problems.

The code inside the if statement doesn't reset all the images to hidden. So you would need to call reset function instead

Your reset function doesn't reset the index.

You should set index 0 to block once, and then loop through the rest instead of setting index 0 to block in each iteration.

Because you reset when index == 3, you will never see the last image. You should reset on the following iteration to ensure that each image is visible for one second.

See my example below.

var images = document.querySelectorAll(".slide-img");
var index = 0;
var time = 1000;

function reset(){
  index = 0;
  images[0].style.display = 'block';
  for(var i = 1; i < images.length; i++){
    images[i].style.display = 'none';
  }
}

reset();

setInterval(function(){
  index++;
  if(index >= images.length){
    reset();
  } else {
   images[index].style.display = 'block';
  }
}, 1000);

.container {
  display: flex;
}

.slide-img {
  width: 100px;
  height: 100px;
}

<div class="container">
  <div class="slide-img" style="background: red"></div>
  <div class="slide-img" style="background: blue"></div>
  <div class="slide-img" style="background: green"></div>
  <div class="slide-img" style="background: purple"></div>
</div>

If you have other question on why my code is different than yours, ask in the comments. But I think the code should be clear and understandable.


问:
How to know whether dataset/datatable contains CLOB data without reading any rows
I have this reading datatable or dataset. If the data contains clob data, then file name has to changed.

But we first create the file and then come across the clob data. Is there anyway we can find the datatable contains clob data and then create the file.

Thanks,

答: Use DBMS_LOB.GETLENGTH to see if there is more than 0 bytes.</p>

ContentLicense: CC BY-SA 2.5


问:
WordPress footer above content
Sorry, I'm a complete newbie at this, My question may sound stupid to some.
I've taken over maintenance of a WordPress site done by another developer who's no longer reachable. I'm having trouble with getting the content to display properly on the following page https://www.covalin.com/product-category/boxes/metallic-boxes/, when I change the number of products to be shown on the page to anything higher than 9, then it pushes the footer to the middle of the page and shows products below the footer. I want to be able to all products under each subcategory. Please see the screenshots below in order to get an idea of the issue. Any guidance will be most appreaciated, I've spent hours trying to figure this out.

When I use the following CSS below, it partly solves the problem but creates another one where all of the content is scrollable but appears behind the footer.

CSS Code - used

```<code>.footer {
 position: fixed;
 bottom:0;
 }
</code>```

PHP Code which changes the number of products display, added by last dev:

```<code>/*---------- woo-product pagination number setting ------------*/

add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );

function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value
stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 27; //I changed this from 27 to 9 for the page to display properly.
return $cols;
}
</code>```

How the site looks like with 9 products on a page

How the site looks like with 27 products on a page

Updated - with footer.php file below

<?php
/**
 * The template for displaying the footer
 *
 * Contains footer content and the closing of the #main and #page div elements.
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
?>

<?php // Check if site turned to boxed version
   $boxed = ''; $boxed_element = ''; $row_class = '';
   if (get_option('site_layout')=='boxed') {$boxed = 'container'; $boxed_element = 'col-md-12 col-sm-12'; $row_class = 'row';}
?>

  <?php if ($boxed && $boxed!='') { ?>

  <?php } ?>

<?php if ( class_exists('Woocommerce') ): ?>
 <?php  if(is_shop() || is_product() && is_active_sidebar('footer-bottom-shop')): ?>

 <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

            <?php dynamic_sidebar('footer-bottom-shop'); ?>

 <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>
 <?php endif ?>
<?php endif ?>

  <footer id="colophon" class="site-footer <?php echo esc_attr($boxed_element);?>">

   <?php
    if (get_option('site_footer_top_background_option') && get_option('site_footer_top_background_option')!=''){
     $site_footer_top_background_option = get_option('site_footer_top_background_option');
    }
    else{$site_footer_top_background_option='';}
   ?>

  <?php if(is_active_sidebar('footer-top-sidebar-1') || is_active_sidebar('footer-top-sidebar-2')): ?>
   <div class="footer-top widget-area <?php echo esc_attr($row_class);?>" style="background:<?php echo esc_attr($site_footer_top_background_option); ?>;">
    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

     <?php if(is_active_sidebar('footer-top-sidebar-1')): ?>
      <?php dynamic_sidebar('footer-top-sidebar-1'); ?>
     <?php endif;?>

     <?php if(is_active_sidebar('footer-top-sidebar-2')): ?>
      <?php dynamic_sidebar('footer-top-sidebar-2'); ?>
     <?php endif;?>

    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

  <?php endif; ?>

  <?php
    if (get_option('site_middle_background_option') && get_option('site_middle_background_option')!=''){
     $site_middle_background_option = get_option('site_middle_background_option');
    }
    else{$site_middle_background_option='';}
  ?>
   <div class="footer-middle widget-area <?php echo esc_attr($row_class);?>" style="background:<?php echo esc_attr($site_middle_background_option);?>">
    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>
     <?php
      if (get_option('footer_bg_img') && get_option('footer_bg_img')!=''){
      $footer_bg_img_url = get_option('footer_bg_img');
     }
     else{$footer_bg_img_url='';}

     if (get_option('footer_bg_img_position') && get_option('footer_bg_img_position')!=''){
      $footer_bg_img_position = get_option('footer_bg_img_position');
      switch($footer_bg_img_position){
       case "right":
        $storex_footer_bg_position='96%';
        break;
       case "left":
        $storex_footer_bg_position='4%';
        break;
      }
     }
     else{$storex_footer_bg_position='';}

     ?>
      <div class="fotter-bg-img" style="background: url(<?php  echo esc_url($footer_bg_img_url)?>)  no-repeat transparent; background-position:<?php echo esc_attr($storex_footer_bg_position)?> 90%">

        <?php if ( is_active_sidebar( 'footer-sidebar-1' ) ) : ?>
         <?php dynamic_sidebar( 'footer-sidebar-1' ); ?>
        <?php endif; ?>

        <?php if ( is_active_sidebar( 'footer-sidebar-2' ) ) : ?>
        <?php dynamic_sidebar( 'footer-sidebar-2' ); ?>
        <?php endif; ?>

        <?php if ( is_active_sidebar( 'footer-sidebar-3' ) ) : ?>
         <?php dynamic_sidebar( 'footer-sidebar-3' ); ?>
         <?php endif; ?>

        <?php if ( is_active_sidebar( 'footer-sidebar-4' ) ) : ?>
         <?php dynamic_sidebar( 'footer-sidebar-4' ); ?>
        <?php endif; ?>

     <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

   <?php
    if (get_option('site_footer_bottom_background_option') && get_option('site_footer_bottom_background_option')!=''){
     $site_bottom_background_option = get_option('site_footer_bottom_background_option');
    }
    else{$site_bottom_background_option='';}

   ?>

   <div id="footer-bottom" style="background:<?php echo esc_attr($site_bottom_background_option); ?>;" class="<?php echo esc_attr($row_class);?> footer-bottom">
    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

       <?php if (has_nav_menu('footer-nav')) : ?>

         <?php wp_nav_menu( array('theme_location'  => 'footer-nav') ); ?>

      <?php endif; ?>

       <?php $copyright = esc_attr(get_option('site_copyright'));
       if ($copyright != '') {
        echo esc_attr($copyright);
       } else {
        echo 'Storex © '.date('Y') .''.esc_html__(' Theme by Themes Zone. All rights reserved', 'storex');
       }
       ?>

       <?php if ( is_active_sidebar( 'footer-bottom' ) ) : ?>
                             <?php dynamic_sidebar( 'footer-bottom' ); ?>
                         <?php endif; ?>

     <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

  <?php if ($boxed && $boxed!='') { ?>

  <?php } ?>

  <?php wp_footer(); ?>

```

答:
The issue is that you are not closing the
 properly.

Currently it is like

```<code><div id="page" class="hfeed site container">
    <div class='row custom_header'>
       <!-- some contents..... -->
    </div>
    <div class='row'>
        <div id="main" class="site-main col-md-12 col-sm-12">
           <!-- some contents..... -->
        </div>
        <div class='row'>
            <footer id="colophon" class="site-footer col-md-12 col-sm-12">
               <!-- some contents... -->
            </footer>
        </div>
    </div>
</div>
</code>```

It should be like,

```<code><div id="page" class="hfeed site container">
    <div class='row custom_header'>
        <!-- some contents... -->
    </div>
    <div class='row'>
        <div id="main" class="site-main col-md-12 col-sm-12">
            <!-- some contents... -->
        </div>
    </div>
    <div class='row'>
        <footer id="colophon" class="site-footer col-md-12 col-sm-12">
            <!-- some contents... -->
        </footer>
    </div>
</div>
</code>```

There is no need to change the CSS.

Title: WordPress footer above content

Body:
Sorry, I'm a complete newbie at this, My question may sound stupid to some.
I've taken over maintenance of a WordPress site done by another developer who's no longer reachable. I'm having trouble with getting the content to display properly on the following page https://www.covalin.com/product-category/boxes/metallic-boxes/, when I change the number of products to be shown on the page to anything higher than 9, then it pushes the footer to the middle of the page and shows products below the footer. I want to be able to all products under each subcategory. Please see the screenshots below in order to get an idea of the issue. Any guidance will be most appreaciated, I've spent hours trying to figure this out.

When I use the following CSS below, it partly solves the problem but creates another one where all of the content is scrollable but appears behind the footer.

CSS Code - used

.footer {
 position: fixed;
 bottom:0;
 }

PHP Code which changes the number of products display, added by last dev:

/*---------- woo-product pagination number setting ------------*/

add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );

function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value
stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 27; //I changed this from 27 to 9 for the page to display properly.
return $cols;
}

How the site looks like with 9 products on a page

How the site looks like with 27 products on a page

Updated - with footer.php file below

<?php
/**
 * The template for displaying the footer
 *
 * Contains footer content and the closing of the #main and #page div elements.
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
?>

<?php // Check if site turned to boxed version
   $boxed = ''; $boxed_element = ''; $row_class = '';
   if (get_option('site_layout')=='boxed') {$boxed = 'container'; $boxed_element = 'col-md-12 col-sm-12'; $row_class = 'row';}
?>

  <?php if ($boxed && $boxed!='') { ?>

  <?php } ?>

<?php if ( class_exists('Woocommerce') ): ?>
 <?php  if(is_shop() || is_product() && is_active_sidebar('footer-bottom-shop')): ?>

 <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

            <?php dynamic_sidebar('footer-bottom-shop'); ?>

 <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>
 <?php endif ?>
<?php endif ?>

  <footer id="colophon" class="site-footer <?php echo esc_attr($boxed_element);?>">

   <?php
    if (get_option('site_footer_top_background_option') && get_option('site_footer_top_background_option')!=''){
     $site_footer_top_background_option = get_option('site_footer_top_background_option');
    }
    else{$site_footer_top_background_option='';}
   ?>

  <?php if(is_active_sidebar('footer-top-sidebar-1') || is_active_sidebar('footer-top-sidebar-2')): ?>
   <div class="footer-top widget-area <?php echo esc_attr($row_class);?>" style="background:<?php echo esc_attr($site_footer_top_background_option); ?>;">
    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

     <?php if(is_active_sidebar('footer-top-sidebar-1')): ?>
      <?php dynamic_sidebar('footer-top-sidebar-1'); ?>
     <?php endif;?>

     <?php if(is_active_sidebar('footer-top-sidebar-2')): ?>
      <?php dynamic_sidebar('footer-top-sidebar-2'); ?>
     <?php endif;?>

    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

  <?php endif; ?>

  <?php
    if (get_option('site_middle_background_option') && get_option('site_middle_background_option')!=''){
     $site_middle_background_option = get_option('site_middle_background_option');
    }
    else{$site_middle_background_option='';}
  ?>
   <div class="footer-middle widget-area <?php echo esc_attr($row_class);?>" style="background:<?php echo esc_attr($site_middle_background_option);?>">
    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>
     <?php
      if (get_option('footer_bg_img') && get_option('footer_bg_img')!=''){
      $footer_bg_img_url = get_option('footer_bg_img');
     }
     else{$footer_bg_img_url='';}

     if (get_option('footer_bg_img_position') && get_option('footer_bg_img_position')!=''){
      $footer_bg_img_position = get_option('footer_bg_img_position');
      switch($footer_bg_img_position){
       case "right":
        $storex_footer_bg_position='96%';
        break;
       case "left":
        $storex_footer_bg_position='4%';
        break;
      }
     }
     else{$storex_footer_bg_position='';}

     ?>
      <div class="fotter-bg-img" style="background: url(<?php  echo esc_url($footer_bg_img_url)?>)  no-repeat transparent; background-position:<?php echo esc_attr($storex_footer_bg_position)?> 90%">

        <?php if ( is_active_sidebar( 'footer-sidebar-1' ) ) : ?>
         <?php dynamic_sidebar( 'footer-sidebar-1' ); ?>
        <?php endif; ?>

        <?php if ( is_active_sidebar( 'footer-sidebar-2' ) ) : ?>
        <?php dynamic_sidebar( 'footer-sidebar-2' ); ?>
        <?php endif; ?>

        <?php if ( is_active_sidebar( 'footer-sidebar-3' ) ) : ?>
         <?php dynamic_sidebar( 'footer-sidebar-3' ); ?>
         <?php endif; ?>

        <?php if ( is_active_sidebar( 'footer-sidebar-4' ) ) : ?>
         <?php dynamic_sidebar( 'footer-sidebar-4' ); ?>
        <?php endif; ?>

     <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

   <?php
    if (get_option('site_footer_bottom_background_option') && get_option('site_footer_bottom_background_option')!=''){
     $site_bottom_background_option = get_option('site_footer_bottom_background_option');
    }
    else{$site_bottom_background_option='';}

   ?>

   <div id="footer-bottom" style="background:<?php echo esc_attr($site_bottom_background_option); ?>;" class="<?php echo esc_attr($row_class);?> footer-bottom">
    <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

       <?php if (has_nav_menu('footer-nav')) : ?>

         <?php wp_nav_menu( array('theme_location'  => 'footer-nav') ); ?>

      <?php endif; ?>

       <?php $copyright = esc_attr(get_option('site_copyright'));
       if ($copyright != '') {
        echo esc_attr($copyright);
       } else {
        echo 'Storex © '.date('Y') .''.esc_html__(' Theme by Themes Zone. All rights reserved', 'storex');
       }
       ?>

       <?php if ( is_active_sidebar( 'footer-bottom' ) ) : ?>
                             <?php dynamic_sidebar( 'footer-bottom' ); ?>
                         <?php endif; ?>

     <?php if (!$boxed || $boxed=='') : ?>

<?php endif; ?>

  <?php if ($boxed && $boxed!='') { ?>

  <?php } ?>

  <?php wp_footer(); ?>

Body:
The issue is that you are not closing the <div> properly.

Currently it is like

<div id="page" class="hfeed site container">
    <div class='row custom_header'>
       <!-- some contents..... -->
    </div>
    <div class='row'>
        <div id="main" class="site-main col-md-12 col-sm-12">
           <!-- some contents..... -->
        </div>
        <div class='row'>
            <footer id="colophon" class="site-footer col-md-12 col-sm-12">
               <!-- some contents... -->
            </footer>
        </div>
    </div>
</div>

It should be like,

<div id="page" class="hfeed site container">
    <div class='row custom_header'>
        <!-- some contents... -->
    </div>
    <div class='row'>
        <div id="main" class="site-main col-md-12 col-sm-12">
            <!-- some contents... -->
        </div>
    </div>
    <div class='row'>
        <footer id="colophon" class="site-footer col-md-12 col-sm-12">
            <!-- some contents... -->
        </footer>
    </div>
</div>

There is no need to change the CSS.


问:
What are some algorithms to segment character in a word picture

Above is the picture, I want to segment character in TEST to 4 separated images, each contains T,E,S,T respectively and then use CNN to recognize each character. How many algorithms could help this? Could I use RNN with LSTM to do it? Because I prefer neural network but if there is any easier algorithm, please indicate. Thank you so much.

答: On English, all letters are contiguous areas, so you need to do binarization and select (big enough, and not too big) contiguous areas.</p>


问:
debugging MIPS decimal to 8bit binary program
I am trying to write a program which takes in integers one at a time and converts them to 8 bit binary, until 0 is entered and the program terminates, in MIPS. My code is outputting zeros for  even input and 1s for odd. I can't figure out why this is. </p>

```<code>.data
zeroString: .asciiz "00000000\n"

.text

main:
li  $v0, 5      # 5 = syscall code to read int
syscall
beq $v0, 0, exit    #exit when 0 is entered
move    $t0, $v0    #t0=v0
la $t2, 0       #counter

do:         #loop
ANDI $t1, $t0, 0x01 #check if least significant digit is 1
addi $t2, $t2, 1    #increase counter
move $a0, $t1       #printing value of t1
li $v0, 1
syscall
srl $t1, $t1, 1     #shift to next digit
bne $t2, 7, do      #check if counter equal to target

# Print a new line
li  $a0, '\n'   # $a0 = ascii code for newline char
li  $v0, 11     # 11 = syscall code to print char
syscall         # Print newline

j main

exit:
la $a0, zeroString
li $v0, 4
syscall
li $v0, 10
syscall
</code>```

答:
You mean it's printing 8 copies of the low bit (as single-digit integers)?

Single-step your code in the debugger and look at register values change.  Look carefully at which registers you're using as input and output for each instruction in the loop.

You never write $t0, so andi $t1, $t0, 1 produces the same thing every iteration.  Was srl $t1, $t1, 1 supposed to be shifting $t0?  You're actually shifting the temporary that you're about to overwrite.

Body:
I am trying to write a program which takes in integers one at a time and converts them to 8 bit binary, until 0 is entered and the program terminates, in MIPS. My code is outputting zeros for  even input and 1s for odd. I can't figure out why this is.

.data
zeroString: .asciiz "00000000\n"

.text

main:
li  $v0, 5      # 5 = syscall code to read int
syscall
beq $v0, 0, exit    #exit when 0 is entered
move    $t0, $v0    #t0=v0
la $t2, 0       #counter

do:         #loop
ANDI $t1, $t0, 0x01 #check if least significant digit is 1
addi $t2, $t2, 1    #increase counter
move $a0, $t1       #printing value of t1
li $v0, 1
syscall
srl $t1, $t1, 1     #shift to next digit
bne $t2, 7, do      #check if counter equal to target

# Print a new line
li  $a0, '\n'   # $a0 = ascii code for newline char
li  $v0, 11     # 11 = syscall code to print char
syscall         # Print newline

j main

exit:
la $a0, zeroString
li $v0, 4
syscall
li $v0, 10
syscall


问:
How do I convert a C# string to a Span<char>? (Span<T>)
How do I convert a string to a Span<T>?</p>

```<code>Span<char> mySpan = "My sample source string";
</code>```

答:
You need to install the System.Memory NuGet package.

There are extension methods for strings called .AsSpan() or .AsReadOnlySpan() to convert a string to the appropriate Span<T>.

Example:

```<code>Span<char> mySpan = "My sample source string".AsSpan();
ReadOnlySpan<char> myReadOnlySpan = "My read only string".AsReadOnlySpan();
</code>```

Source: MSDN Channel 9 "C# 7.2: Understanding Span" (around the 6 minute mark)

Update: this answer was correct at the time, but based on a preview version. See updated answer on this page by gfoidl for current procedure.

Body:
How do I convert a string to a Span<T>?

Span<char> mySpan = "My sample source string";

Body:
You need to install the System.Memory NuGet package.

There are extension methods for strings called .AsSpan() or .AsReadOnlySpan() to convert a string to the appropriate Span<T>.

Example:

Span<char> mySpan = "My sample source string".AsSpan();
ReadOnlySpan<char> myReadOnlySpan = "My read only string".AsReadOnlySpan();

Source: MSDN Channel 9 "C# 7.2: Understanding Span" (around the 6 minute mark)

Update: this answer was correct at the time, but based on a preview version. See updated answer on this page by gfoidl for current procedure.

ContentLicense: CC BY-SA 4.0