isValidFragment Android API 19 [英] isValidFragment Android API 19
问题描述
当我在 Android KitKat 上试用我的应用时,我在 PreferenceActivity 中出现错误.
When I try my app with Android KitKat I have an error in PreferenceActivity.
PreferenceActivity 的子类必须重写 isValidFragment(String) 以验证 Fragment 类是否有效!com.crbin1.labeltodo.ActivityPreference 没有检查片段 com.crbin1.labeltodo.StockPreferenceFragment 是否有效
Subclasses of PreferenceActivity must override isValidFragment(String) to verify that the Fragment class is valid! com.crbin1.labeltodo.ActivityPreference has not checked if fragment com.crbin1.labeltodo.StockPreferenceFragment is valid
在文档中我找到以下解释
In documentation I find the following explanation
protected boolean isValidFragment (String fragmentName)
protected boolean isValidFragment (String fragmentName)
在 API 级别 19 中添加
Added in API level 19
子类应覆盖此方法并验证给定的片段是要附加到此活动的有效类型.对于为 android:targetSdkVersion 早于 KITKAT 构建的应用程序,默认实现返回 true.后面的版本会抛出异常.
Subclasses should override this method and verify that the given fragment is a valid type to be attached to this activity. The default implementation returns true for apps built for android:targetSdkVersion older than KITKAT. For later versions, it will throw an exception.
我没有找到解决问题的任何示例.
I don't find any example to resolve the problem.
推荐答案
试试这个……这是我们检查片段有效性的方法.
Try this... this is how we check validity of fragment.
protected boolean isValidFragment(String fragmentName) {
return StockPreferenceFragment.class.getName().equals(fragmentName);
}
这篇关于isValidFragment Android API 19的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!