skip to Main Content

MainActivity.java

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;

    private RecyclerView.Adapter mAdapter;

    private RecyclerView.LayoutManager mLayoutManager;
    private ArrayList<WordClass> mWordList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CreateArrayList();

        mRecyclerView = findViewById(R.id.recycler_view);
        mLayoutManager = new LinearLayoutManager(this);
        mAdapter = new WordAdapter(mWordList);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);
    }

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

        mWordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        mWordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        mWordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        mWordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        mWordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
        mWordList.add(new WordClass(R.drawable.ic_face, "Text1", "Text2"));
    }
}
انتقل للدرس الرابع

اترك تعليقاً

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