I want to create a custom row adapter to my Android application. So I have build this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="5dp"
android:clickable="true"
android:orientation="vertical">
<TextView
android:id="@+id/medication"
android:textColor="@color/white"
android:textSize="16dp"
android:textStyle="bold"
android:layout_width="120dp"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/instructions"
android:textColor="@color/white"
android:layout_toRightOf="@+id/medication"
android:layout_width="170dp"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/startDate"
android:textColor="@color/white"
android:layout_width="100dp"
android:layout_toRightOf="@+id/instructions"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/active"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_toRightOf="@+id/startDate"
android:layout_height="wrap_content"
/>
</RelativeLayout>
Now I have build this adaptor class "MedicationAdapter.java":
public class MedicationAdapter extends RecyclerView.Adapter<MedicationAdapter.MyMedicationViewHolder> {
private List<Medication> moviesList;
public class MyMedicationViewHolder extends RecyclerView.ViewHolder {
public TextView medication, instruction, startDate,active;
public MyMedicationViewHolder(View view) {
super(view);
medication = (TextView) view.findViewById(R.id.medication);
instruction = (TextView) view.findViewById(R.id.instructions);
startDate = (TextView) view.findViewById(R.id.startDate);
active = (TextView) view.findViewById(R.id.active);
}
}
public MedicationAdapter(List<Medication> moviesList) {
this.moviesList = moviesList;
}
@Override
public MyMedicationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.medications_list_row, parent, false);
return new MyMedicationViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyMedicationViewHolder holder, int position) {
Medication medication = moviesList.get(position);
holder.medication.setText(medication.getDrugInfo().getDisplayName());
holder.instruction.setText(medication.getFrequency()+" "+ medication.getDose());
holder.startDate.setText(medication.getDateStart());
holder.active.setText("SI");
}
@Override
public int getItemCount() {
return moviesList.size();
}
}
Now if I try to run my Android application, I can see my activity like this:
Now I want to insert a title Text in the head of this list, and I want to insert a border line to every cell.
It is possible to do this?
regards