【发布时间】:2014-05-24 15:52:36
【问题描述】:
我正在尝试从 FragmentActivity 类访问 Fragment 方法并更改该 Fragment 布局中的一些 TextView。
我的 MainActivity 扩展了 FragmentActivty (v4) 及其布局 -> activity_main.xml:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
SelectionFragment 类扩展了具有 updateLoadMembersData() 方法 (v4) 及其布局的 Fragment -> selection_fragment.xml 其中包含,标签等。
在 MainActivity 类中,我尝试运行此代码:
protected void onResume() {
super.onResume();
viewPager.setCurrentItem(0);
SelectionFragment instanceFragment = (SelectionFragment) getSupportFragmentManager().findFragmentById(R.layout.selection_fragment);
instanceFragment.updateLoadMembersData();
Toast.makeText(this, "Saved Data Succesfully Added!", Toast.LENGTH_LONG);
}
instanceFragment.updateLoadMembersData();
此方法尝试更改一些 textViews editTexts 等我无法运行此方法。
但是我遇到了诸如 ClassCastException 之类的错误,我看了一些类似的问题,但找不到合理的解决方案。我没有片段/片段标签,我在 activity_main 中只有 /android.support.v4.view.ViewPager。 xml.
【问题讨论】:
标签: java android xml android-layout android-fragments