在主要活动中我有这个
public void showTimePickerDialog(View v) {
DialogFragment newFragment = new uSharedUtility.TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker");
}
但是我收到了这个错误:
Error:(566, 26) error: cannot find symbol method getSupportFragmentManager()
搜索后我发现我可以让它消失by extending from FragmentActivity
但是由于之前的一些要求,目前我的MainActivity正在从public class Main extends ListActivity
延伸。
除了更改扩展类之外,还有其他任何方法可以解决此问题吗?
答案 0 :(得分:6)
getSupportFragmentManager() 是 FragmentActivity 的方法。您的父活动应该扩展FragmentActivity
检查
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
答案 1 :(得分:0)
There are other reasons for the same error message. You might need to instead call getFragmentManager()
As noted in the accepted answer to this related thread: Difference between Fragment And FragmentActivity