In Android Studio, select File → New Project... to create a new project. Start with the Add No Activity option for Phone and Tablet. Name the app NerdLauncher and give it a package name of com.bignerdranch.android.nerdlauncher. Select the option to Use AndroidX artifacts and leave the rest of the defaults as they are.
Once Android Studio has initialized the project, create a new empty activity using File → New → Activity → Empty Activity. Name the activity NerdLauncherActivity and check the Launcher Activity box.
NerdLauncherActivity will display a list of application names in a RecyclerView.
Add the androidx.recyclerview:recyclerview:1.0.0
dependency to app/build.gradle, as you did in Chapter 9. If you would like to use newer versions of RecyclerView, you can find the latest release versions at developer.android.com/jetpack/androidx/releases/recyclerview.
Replace the contents of layout/activity_nerd_launcher.xml with the RecyclerView shown in Listing 23.1.
Listing 23.1 Updating the NerdLauncherActivity
layout (layout/activity_nerd_launcher.xml
)
<?xml version="1.0" encoding="utf-8"?> <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/app_recycler_view" android:layout_width="match_parent" android:layout_height="match_parent"/>
Open NerdLauncherActivity.kt and stash a reference to the RecyclerView object in a property. (You will hook data up to the RecyclerView in just a bit.)
Listing 23.2 Basic NerdLauncherActivity
implementation (NerdLauncherActivity.kt
)
class NerdLauncherActivity : AppCompatActivity() { private lateinit var recyclerView: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_nerd_launcher) recyclerView = findViewById(R.id.app_recycler_view) recyclerView.layoutManager = LinearLayoutManager(this) } }
Run your app to make sure everything is hooked up correctly to this point. If so, you will be the proud owner of an app titled NerdLauncher, displaying an empty RecyclerView (Figure 23.2).
3.84.231.140