Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
a. RecyclerAdapter.ViewHolder<TrainAdapter.ViewHolder>
b. RecyclerAdapter<TrainAdapter.ViewHolder>
c. RecyclerView.Adapter<TrainAdapter.ViewHolder>
d. TrainAdapter.ViewHolder<RecyclerView.Adapter>
Only option (c) makes sense here. We are subclassing a RecyclerView.Adapter of
type TrainAdapter.ViewHolder. (d) is the wrong way around, (a) and (b) are
nonsense as there is no such class as RecyclerAdapter.
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.mad.exercise5"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
}
a. 0
b. 1
c. 2
d. 3
a. 0
b. 1
c. 2
d. 3
The last line is an obvious error as the Intent class has no putExtras method (it is
putExtra). The first argument should be a String, so the third one is also a compile
error.
@Override
protected Void doInBackground(Void... params)
{
// Simulate the download process by sleeping for some period of time
try {
Thread.sleep(FILE_DOWNLOAD_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
mProgressDialog.dismiss();
return null;
}
a. Yes
b. No
We shouldn’t modify the UI from a background thread. Instead use
onProgressUpdate and onPostExecute methods.
6. Is this correct?
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
mProgressDialog.setMessage(getFormattedString (R.string.downloading,
values[0]));
mProgressDialog.incrementProgressBy(1);
}
a. Yes
b. No
Yes. This is executed in the context of the UI thread; your background task uses
publishProgress to asynchronously provide updates which are used by this method
to update the UI.
a. Yes
b. No
The Spinner is a local variable, so it shouldn’t be prefixed with m. Everything else is
OK.