Le bouton devrait ouvrir une nouvelle activité et devrait afficher les informations de cette seule carte particulière dont le bouton a été cliquécliquez sur le bouton dans RecyclerView
J'ai 6 cartes à RecyclerView aussi j'extraire des données de Firebase
Mon code RecyclerView:
public class index extends AppCompatActivity {
private Toolbar toolbar;
private RecyclerView recyclerView;
private DatabaseReference myRef;
private FirebaseAuth firebaseAuth;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.index);
firebaseAuth = FirebaseAuth.getInstance();
myRef = FirebaseDatabase.getInstance().getReference().child("/Doctor");
if(firebaseAuth.getCurrentUser() == null)
{
startActivity(new Intent(this, MainActivity.class));
}
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
FirebaseRecyclerAdapter<Listitem,ListItemHolder> adapter = new
FirebaseRecyclerAdapter<Listitem, ListItemHolder>(
Listitem.class,
R.layout.list_item,
ListItemHolder.class,
myRef
) {
@Override
protected void populateViewHolder(ListItemHolder ItemHolder,
Listitem model, int position) {
ItemHolder.setDocName(model.getDocName());
ItemHolder.setSpeciality(model.getSpeciality());
ItemHolder.setAddress(model.getAddress());
ItemHolder.setExperience(model.getExperience());
ItemHolder.setFees(model.getFees());
ItemHolder.bookButton.setOnClickListener(new
View.OnClickListener(){
public void onClick(View v){
Intent i = new Intent(index.this, Booking.class);
startActivity(i);
}
});
}
};
recyclerView.setAdapter(adapter);
}
public static class ListItemHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
TextView head,desc,desc1,desc2,desc3;
Button bookButton;
public ListItemHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
head = (TextView) itemView.findViewById(R.id.textViewHead);
desc = (TextView) itemView.findViewById(R.id.textViewDesc);
desc1 = (TextView) itemView.findViewById(R.id.textViewDesc1);
desc2 = (TextView) itemView.findViewById(R.id.textViewDesc2);
desc3 = (TextView) itemView.findViewById(R.id.textViewDesc3);
this.bookButton = (Button)
itemView.findViewById(R.id.bookButton);
}
public void setDocName(String DocName) {
head.setText(DocName);
}
public void setSpeciality(String Speciality) {
desc.setText(Speciality);
}
public void setAddress(String Address) {
desc1.setText(Address);
}
public void setExperience(String Experience) {
desc2.setText(Experience);
}
public void setFees(String Fees) {
desc3.setText(Fees);
}
@Override
public void onClick(View view) {
}
}
}
CardLayout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/greyshade"
android:fitsSystemWindows="true">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:padding="@dimen/cardview_default_radius"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
>
<TextView
android:id="@+id/textViewHead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Heading"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="@dimen/text_size"
/>
<TextView
android:id="@+id/textViewDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/Desc"/>
<TextView
android:id="@+id/textViewDesc1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Desc"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/textViewDesc2"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="@color/black"
android:maxLines="1"
android:textSize="12sp"
android:text="@string/Desc"/>
<TextView
android:id="@+id/textViewDesc3"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:textSize="12sp"
android:maxLines="1"
android:text="@string/Desc"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/bookButton"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/Book"
android:textColor="@color/textbutton"
android:textStyle="bold"
android:backgroundTint="@color/bookbutton"
android:layout_marginStart="130dp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Mise à jour
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewHead"
android:text="@string/Heading"
android:layout_marginTop="30dp"
android:textStyle="bold"
android:textColor="@color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewDesc1"
android:text="@string/Desc"
android:layout_marginTop="20dp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<android.support.v7.widget.AppCompatButton
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Logout"
android:layout_marginBottom="45dp"/>
</RelativeLayout>
</LinearLayout>
Quel est exactement le problème? Votre bouton n'ouvre pas l'activité? Les informations que vous souhaitez afficher ne sont pas affichées dans la nouvelle activité? S'il vous plaît élaborer. –
En appliquant l'intention, le bouton ouvre la nouvelle activité mais ne montre pas l'information @antonis_st –
@VismayPatil attendez que je poste la réponse –