My code is:
public static void ToastMemoryShort (Context context) {
CharSequence text = getString(R.string.toast_memoryshort); //error here
Toast.mak
You could make your toast more generic like this:
public void toast(String msg){
Context context = getApplicationContext();
CharSequence text = msg;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
Then just call when you need like this:
toast( "My message hardcoded" );
or by referring to strings.xml like this:
toast( this.getString(R.string.toast_memoryshort) );
Use the below code to get the desired output:
Toast.makeText(getApplicationContext(),getString(R.string.exit_survey_toast),Toast.LENGTH_LONG).show();
replace exit_survey_toast with your string value.
You should change
CharSequence text = getString(R.string.toast_memoryshort); //error here
for:
CharSequence text = context.getString(R.string.toast_memoryshort);
The getString function is implemented in Context#getString(int)
Just use this instead:
makeText(Context context, int resId, int duration) Make a standard toast that just contains a text view with the text from a resource.
From http://developer.android.com/reference/android/widget/Toast.html
Change to
public static void ToastMemoryShort (Context context) {
Toast.makeText(context, context.getString(R.string.toast_memoryshort), Toast.LENGTH_LONG).show();
return;
}