我在 my 的布局中定义了两个片段,MainActivity
并由setContentView
. 我想从这些片段中调用一些方法,但我不知道如何访问它们。Eclipse 说:“无法将表单片段转换为 ListFileFrgament”。
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FileListFragment listFragment = (FileListFragment) getFragmentManager().findFragmentById(R.id.list_fragment);
// cannot casr here
PlayerFragment playerFragment = (PlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
// cannot cast here
}
}