Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

On Android Studio do i have to retrieve value of a string token, use getResource

ID: 3878682 • Letter: O

Question

On Android Studio do i have to retrieve value of a string token, use getResources.getString() ; syntax is: String greeting = getResources().getString(R.string.hello); R is automatically generated and string is a static class, “hello” is the name of the string in “strings.xml” and also declare Define a variable (global)– in onSaveInstanceState, increment it by 1 and save it to the bundle; in onRestoreInstanceState, set variable to the value stored in the bundle and print it to the log file???

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For each callback events (onCreate(), onStart()… ), record what callback event was triggered in the log(use Log.d); the message that is written to log should be defined in “strings.xml” and getResources.getString() should be used to retrieve the message

Implement onSaveInstanceState and onRestoreInstanceState – to track the number of times onSaveInstanceState is being called, in onRestoreInstanceState, print the value to the log file

Tag for “Log” statement should also be defined in strings.xml and set using getResources.getString()

Explanation / Answer

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.StringWriter;

import java.net.MalformedURLException;

import java.net.URISyntaxException;

import java.net.URL;

import java.text.NumberFormat;

import java.text.ParseException;

import java.util.List;

import java.util.Properties;

import static com.android.SdkConstants.DOT_WEBP;

import static com.android.SdkConstants.DOT_XML;

{

return false;

}

public static String escapePropertyValue(@NonNull String value)

{

  

Properties properties = new Properties();

properties.setProperty("k", value);

StringWriter writer = new StringWriter();

try

{

properties.store(writer, null);

String s = writer.toString();

int end = s.length();

String lineSeparator = SdkUtils.getLineSeparator();

if (s.endsWith(lineSeparator))

{

end -= lineSeparator.length();

}

int start = s.indexOf('=');

assert start != -1 : s;

return s.substring(start + 1, end);

}

catch (IOException e)

{

return value;

}

}

}

import android.content.res.Resources;

import android.content.res.TypedArray;

import android.support.annotation.Nullable;

import android.os.Bundle;

import android.support.v7.widget.GridLayoutManager;

import android.app.Activity;

public void onAttach(Context context)

{

super.onAttach(context);

  

final Resources resources = context.getResources();

mNames = resources.getStringArray(R.array.names);

mDescriptions = resources.getStringArray(R.array.descriptions);

mUrls = resources.getStringArray(R.array.urls);

final TypedArray typedArray = resources.obtainTypedArray(R.array.images);

final int imageCount = mNames.length;

mImageResIds = new int[imageCount];

for (int i = 0; i < imageCount; i++)

{

mImageResIds[i] = typedArray.getResourceId(i, 0);

}

typedArray.recycle();

}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

{

final View view = inflater.inflate(R.layout.fragment_rage_comic_list, container, false);

1111 final Activity activity = getActivity();

final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);

recyclerView.setLayoutManager(new GridLayoutManager(activity, 2));

recyclerView.setAdapter(new RageComicAdapter(activity));

return view;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote