Professional Documents
Culture Documents
1. Judul Tugas
Mahasiswa.java :
package com.example.recyclerview;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
holder.txtAngkatan.setText(dataList.get(position).getAngakatan());
holder.Vfoto.setImageResource(dataList.get(position).getFoto());
}
@Override
public int getItemCount() {
return (dataList != null) ? dataList.size() : 0;
}
MainActivity( .java) :
package com.example.recyclerview;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList;
addData();
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
}
private void addData(){
mahasiswaArrayList = new ArrayList<>();
mahasiswaArrayList.add(new Mahasiswa("Vina", "1718019","2017",
R.drawable.hijab1));
mahasiswaArrayList.add(new Mahasiswa("Hana", "1718002", "2017",
R.drawable.hijab2));
mahasiswaArrayList.add(new Mahasiswa("Lola", "1718031", "2017",
R.drawable.hijab3));
mahasiswaArrayList.add(new Mahasiswa("Sasa", "1718031", "2017",
R.drawable.hijab4));
}
}
Gradient_background.XML :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="45"
android:startColor="@color/pertama"
android:endColor="@color/kedua">
</gradient>
</shape>
Activity_main.XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/gradient_background">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Item_mahasiswa.XML :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.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"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="3dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:background="@drawable/gradient_background">
<androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="80dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/viewfoto">
</ImageView>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:layout_margin="5dp"
android:background="@drawable/gradient_background">
<TextView
android:id="@+id/txt_nama_mahasiswa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"/>
<TextView
android:id="@+id/txt_nim_mahasiswa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"/>
<TextView
android:id="@+id/txt_angkatan_mahasiswa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Colors.XML :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#006D5F</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#EE1515</color>
<color name="pertama">#B315CF</color>
<color name="kedua">#0BF3A9</color>
</resources>
String.XML :
<resources>
<string name="app_name">RecyclerView</string>
</resources>
Styles.XML :
<resources>
</resources>