我遇到了一个问题,我似乎无法理解为什么会发生这样的问题。我使用support v4库(版本21.0.3)在我的项目中获得了一些片段。在这些片段中,我使用getContext()方法来显示Toasts。 但昨天突然在我的项目中所有getContext都破了,Android Studio在编译时向我显示了26个错误。这是打破
的多个例子之一textView.text = nil;
textView.attributedText = nil;
textView.attributedText = [[NSAttributedString alloc] initWithString:@"your new string"];
从我在Android文档中看到的内容(http://developer.android.com/reference/android/support/v4/app/Fragment.html#getContext())中,getContext是support-v4 Fragment的一种方法,因此我一直试图弄清楚问题是什么。< / p>
在该项目中,我还有一个ViewPager,我不能在addOnPageListener方法中遇到同样的问题。
我尝试使用Gradle文件重建项目并重新启动项目,但无济于事。
感谢。
答案 0 :(得分:1)
Fragment#getContext()
was added in version 23 of the support library。如果您无意中将build.gradle文件翻转为使用旧版本(例如21.0.3),则不支持getContext()
。