My code is:
public static void ToastMemoryShort (Context context) {
CharSequence text = getString(R.string.toast_memoryshort); //error here
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
return;
}
but I'm getting "Cannot make a static reference to the non-static method getString(int) from the type Context" in Eclipse. I'm trying to get ready for localising my app (getting all the hard coded strings into resources), so where I have:
getString(R.string.toast_memoryshort)
I previously had a hard coded string which was fine.
I'm not sure what's going on here (Java noob). Can anyone enlighten me please?
Many thanks
Baz
Text : It is the string message that you want the toast to display on the Android Activity screen. String toastTextMsg = "Hello, welcome to Code2care!"; Toast toast = Toast. makeText(MainActivity.
android:text="@string/hello" />String string = getString (R. string. hello);
On Button click call displayValue() to display the toast message with the value set to cText. Show activity on this post. cText sounds like a character sequence or at the least some kind of text. Assuming that its a character sequence or String: yes you can use it.
Therefore the code to make a Toast message is: Toast. makeText(getApplicationContext(), "This a toast message", Toast. LENGTH_LONG);
Change to
public static void ToastMemoryShort (Context context) {
Toast.makeText(context, context.getString(R.string.toast_memoryshort), Toast.LENGTH_LONG).show();
return;
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With