xml 레이아웃에서 ListFragment를 찾으려고하면 항상 null이 반환됩니다. SherlockFragmentActivity를 SherlockListFragment와 함께 사용하고 있습니다.findFragmentById는 항상 null입니다.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_custom_layout);
adapter = new My_Custom_Adapter(this, My_Object, My_Object_2);
}
// Create the list fragment and add it as the list content.
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
mListFragment list = new mListFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, list).commit();
}
}
public static class mListFragment extends SherlockListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(adapter);
setListShown(true);
}
}
이것은 XML 레이아웃의 단축 버전입니다 :
<RelativeLayout
android:id="@+id/top_control_bar">
<!-- Text Views -->
</RelativeLayout>
<RelativeLayout >
<!-- Button -->
</RelativeLayout>
<LinearLayout
android:id="@+id/start_data"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/top_control_bar"
android:orientation="vertical" >
<fragment
android:name="android.support.v4.app.ListFragment"
android:id="@android:id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
findFragmentById(android.R.id.content)
는 항상 null을 반환 여기에 코드입니다. 내 레이아웃 내에서 조각을 찾을 수없는 이유는 무엇입니까?
:. 당신이 시도해보십시오 SupportMapFragment
가 필요합니다, 그래서
에서 getSupportFragmentManager() findFragmentById (android.R.id.content)는 지원 조각 관리자를 사용합니다. – DaveSav
무슨 뜻인가요? [문서] [1]에서 잘못된 구문을 사용하고있는 것처럼 보입니다. [1] : http://developer.android.com/guide/components/fragments.html#Adding – DigCamara
xml을 제안 사항으로 변경했지만 불행하게도 아무런 변화가 없었습니다. – DaveSav