• Uncategorized
  • 0

4.4: Create a Recycler View

Task 1. Create and configure a new project

1.1. Create the project

buat project baru seperti dibawah :

1.2. Add support libraries to the build file

masukkan compiler seperti dibawah, sesuaikan dengan compiledSdkVerson yang ada di android studio masing-masing, jika perlu “sync now” untuk menghindari error building

Task 2. Create a dataset

2.1. Add code to create data

dalam task ini kita membuat linked list, buka MainActivity.java lalu masukkan kodingan dibawah

lalu run, tidak ada yang berubah dari tampilan layout hanya saja di logcat akan tampak seperti berikut

Task 3. Create a RecyclerView

3.1. Create the main layout in activity_main.xml

dalam task ini kota memakai CoordinatorLayout yang merupakan layout yang lebih fleksibel daripada LinearLayout ketika menyusun Views. caranya :

  1. pastikan build:gradle(module app) tedapat :
    compile 'com.android.support:recyclerview-v7:26.1.0'
  2. lalu kemudian masukkan kodingan seperti dibawah :

3.2. Create the layout for one list item

buka res-layout lalu klik kanan pilih new- layout resource file

namai resource dengan nama berikut lalu ok

lalu masukkan kodingan di dalam layout-nya

3.3 Create a style from the TextView attributes

 arahkan kursor ke TextView lalu klik kanan pilih refactor-extract-style

setelah itu isikan nama style sebagai berikut

pilih whole project

buka styles.xml maka style dari TextView akan berpindah lalu Textview pada Wordlist_item.xml hanya diwakilkan oleh styles=”@styles/word_title”

jika aplikasi di run maka akan seperti berikut

3.4. Create an adapter with a view holder

3.5 Create the view holder

notes : jika terdapat error lakukan implement method

catat warning dibawah ini yang ada pada logcat

hasil dari task ini akan tetap sama yaitu masih blank page tapi run saja untukmemastikan jika tidak terdapat error lagi

3.6 Storing your data in the adapter

jika menemukan error dibawah, kita akan memperbaikinya di task selanjutnya

3.7. Create the RecyclerView in the Main Activity

Task 4. Make the list interactive

4.1. Make items respond to clicks

Task 5. Add a FAB to insert items

5.1. Add a Floating Action Button (FAB)

The FAB is a standard control from the Material Design Specification and is part of the Android Design Support Library.

Note the following:

  • <code>@+id/fab </code>It is customary to give the FAB the “fab” id.
  • android:layout_gravity="bottom|end". The FAB is commonly placed at the bottom and at the end of the reading/writing flow.
  • android:src="@drawable/ic_add_black_24dp". Is marked red by Android Studio because the resource is missing

klik kanan pada drawable-new-vector asset

pastikan asset type : material icon, lalu pilih icon + seperti dibawah, biarkan peraturan default lainnya lalu klik ok, next,finish

Android provides an icon library for standard Android icons. ic_add_black_24dp is one of the standard icons.

5.2. Add behavior to the FAB

In this task you’ll add to the FAB an onClick listener that does the following:

  • Adds a word to the end of the list of words.
  • Notifies the adapter that the data has changed.
  • Scrolls to the inserted item.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *