これはかなり簡単だと思っていたのですが、想像以上に難しいことがわかりました。フラグメントの1つで、両方のフラグメントが画面に表示されるタイミングを確認したいだけです。onCreate
最適な場所かどうかはわかりませんが、、、、、を試しonResume
てみましonActivityCreated
た。フラグメントは、後でコードに実際に表示されないと思いますが、確かではありません。onResume
onCreateView
onAttach
これは私が使おうとしているコードです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<fragment android:name="com.app.Fragment1"
android:id="@+id/fragment1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
/>
<fragment android:name="com.app.Fragment2"
android:id="@+id/fragment2"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="fill_parent"
/>
</LinearLayout>
public class Fragment2 extends SherlockListFragment
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
final Fragment1 f1 = (Fragment1)getFragmentManager().findFragmentById(R.id.fragment1);
final Fragment2 f2 = (Fragment2)getFragmentManager().findFragmentById(R.id.fragment2);
Boolean isVisible = (f1 != null && f1.isVisible() && f2 != null && f2.isVisible());
}
}