using a string resource in a Toast

前端 未结 5 1586
不知归路
不知归路 2020-12-18 23:25

My code is:

public static void ToastMemoryShort (Context context) {
    CharSequence text = getString(R.string.toast_memoryshort); //error here
    Toast.mak         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 23:56

    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)

提交回复
热议问题