Skip to content
Snippets Groups Projects
Commit a656cba9 authored by Valentin Bout's avatar Valentin Bout
Browse files

feat: recyclerview with card

parent 99802b5a
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.10369430215581076" />
<entry key="app/src/main/res/layout/card.xml" value="0.335" />
<entry key="app/src/main/res/layout/text_col_item.xml" value="0.15070921985815602" />
<entry key="app/src/main/res/layout/text_row_item.xml" value="0.10118367232181781" />
</map>
......
......@@ -32,6 +32,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.cardview:cardview:1.0.0"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
......
package com.example.tp_reclyclerview;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
public class CardRecyclerViewAdapter extends RecyclerView.Adapter<CardRecyclerViewAdapter.ViewHolder> {
private String[] localDataSet;
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView textViewPos;
private final TextView textViewText;
public ViewHolder(View view) {
super(view);
textViewPos = (TextView) view.findViewById(R.id.card_pos_tv);
textViewText = (TextView) view.findViewById(R.id.card_text_info);
}
public TextView getTextViewPos() {
return textViewPos;
}
public TextView getTextViewInfo() {
return textViewText;
}
}
public CardRecyclerViewAdapter(String[] data) {
localDataSet = data;
}
public CardRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.card, viewGroup, false);
return new CardRecyclerViewAdapter.ViewHolder(view);
}
@Override
public void onBindViewHolder(CardRecyclerViewAdapter.ViewHolder viewHolder, final int position) {
viewHolder.getTextViewPos().setText("" + position);
viewHolder.getTextViewInfo().setText(localDataSet[position]);
}
@Override
public int getItemCount() {
return localDataSet.length;
}
}
\ No newline at end of file
......@@ -21,9 +21,9 @@ public class MainActivity extends AppCompatActivity {
genDatas(100);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
TextColRecyclerViewAdapter adapter = new TextColRecyclerViewAdapter(datas);
CardRecyclerViewAdapter adapter = new CardRecyclerViewAdapter(datas);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new GridLayoutManager(this, spawnCount, GridLayoutManager.HORIZONTAL, false));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
public String genRandomStr(int str_length) {
......@@ -46,7 +46,7 @@ public class MainActivity extends AppCompatActivity {
public void genDatas(int number) {
datas = new String[number];
for(int i = 0; i < number; i++) {
datas[i] = genRandomStr(number*1000);
datas[i] = genRandomStr(number*10);
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:backgroundTint="#5983AF"
app:cardCornerRadius="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/card_pos_tv"
android:layout_width="60dp"
android:layout_height="30dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/card_pos_tv"
app:layout_constraintTop_toBottomOf="@+id/card_pos_tv" />
<TextView
android:id="@+id/card_text_info"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="@+id/imageView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView3"
app:layout_constraintTop_toTopOf="@+id/imageView3" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment