In our TeaViewModel class, that extends ViewModel, we have such prorerty:
val tea: LiveData
An observer in our Activity (type of mViewModel variable in example is TeaViewModel) is set in this way:
mViewModel!!.tea.observe(this, Observer { tea: Tea? -> displayTea(tea) })
What will be a correct displayTea method definition?
In general, you should send an AccessibilityEvent whenever the content of your custom view changes. For example, if you are implementing a custom slider bar that allows a user to select a numeric value by pressing the left or right arrows, your custom view should emit an event of type TYPE_VIEW_TEXT_CHANGED whenever the slider value changes. Which one of the following sample codes demonstrates the use of the sendAccessibilityEvent() method to report this event.
For example, we have a file in our raw folder app/src/main/res/raw/sample_teas.json. To get an
InputStream for reading it, from out Context context, we can do this:
The diagram below shows a basic form of the recommended architecture for apps that use Architecture Components. The architecture consists of a UI controller, a ViewModel that serves LiveData, a Repository, and a Room database. Drag modules to correct places.
LiveData.postValue() and LiveData.setValue() methods have some differences. So if you have a following code executed in the main thread:
liveData.postValue("a"); liveData.setValue("b");
What will be the correct statement?
As an example. In an Activity we have our TimerViewModel object (extended ViewModel), named mTimerViewModel. mTimerViewModel.timer method returns a LiveData
RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists. Instead of creating a View for each item that may or may not be visible on the screen, RecyclerView:
Assume that you have the following situation: The app code calls for R.string.text_a Three relevant resource files are available:
-res/values/strings.xml, which includes text_a in the app's default language, in this case English.
-res/values-mcc404/strings.xml, which includes text_a in the app's default language, in this case English.
-res/values-hi/strings.xml, which includes text_a in Hindi.
The app is running on a device that has the following configuration:
-The SIM card is connected to a mobile network in India (MCC 404).
-The language is set to Hindi (hi).
Which is the correct statement below?
The easiest way of adding menu items (to specify the options menu for an activity) is inflating an XML file into the Menu via MenuInflater. With menu_main.xml we can do it in this way:
For example, suppose that in a XML file (res/menu/menu_main.xml as an example), where menu items are described, we have such item:
...
android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/menu_action_settings" app:showAsAction="never" /> ... Attribute “app:showAsAction” shows when and how this item should appear as an action item in the app bar. What value “never” in this attribute means?
What method should we use with Notification.Builder to supply a PendingIntent to be sent when the notification is clicked?
Android uses adapters (from the Adapter class) to connect data with View items in a list. There are many different kinds of adapters available, and you can also write custom adapters. To connect data with View items, the adapter needs to know about the View items. From what is extended the entity that is usually used in an adapter and describes a View item and its position within the RecyclerView?
What do you want from Room when you create a DAO method and annotate it with @Update?
Example:
@Dao
public interface MyDao {
@Update
public void updateUsers(User... users);
}
“workManager” is an instance of WorkManager. Select correct demonstration of WorkRequest cancellation:
What public methods are there in android.widget.Toast.Callback? (Choose two.)