skip to Main Content

Dependencies

 //Recycler view
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    //card view
    implementation 'com.android.support:cardview-v7:28.0.0'

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp"
        android:scrollbars="vertical"
        android:id="@+id/recycler_view"/>

</android.support.constraint.ConstraintLayout>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <ImageView
            android:id="@+id/image_view"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_face" />

        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/image_view"
            android:padding="3dp"
            android:text="text1"
            android:textSize="20dp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/text1"
            android:layout_toEndOf="@id/image_view"
            android:padding="3dp"
            android:text="text2"
            android:textSize="20dp"
            android:textStyle="bold" />

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

WordClass.java

public class WordClass {

    private int mImageView;
    private String mTextView1;
    private String mTextview2;

    public WordClass(int imageRes, String text1, String text2)
    {
        mImageView = imageRes;
        mTextView1 = text1;
        mTextview2 = text2;
    }

    public int getmImageView() {
        return mImageView;
    }

    public String getmTextView1() {
        return mTextView1;
    }

    public String getmTextview2() {
        return mTextview2;
    }
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CreateArrayList();

    }

    public void CreateArrayList() {
        ArrayList<WordClass> wordList = new ArrayList<>();

        wordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        wordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        wordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        wordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        wordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        wordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
    }
}
انتقل للدرس الثاني ,,

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *