I want to create a list in fragment (some thing like left navigation). For this I used following code but not able to populate the list in fragment.
Main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment android:id="@+id/categoryList"
android:layout_height="fill_parent"
android:name="com.example.fragments.CategoryListFragment"
android:layout_width="wrap_content" />
</LinearLayout>
MainActivity:
public class MainActivity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
CategoryListFragment class:
public class CategoryListFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] values = new String[] { "AAAA", "BBBB", "CCCC" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
}
In my code I was including a layout for header in main.xml something like:
When I removed it all things are working fine. Anybody can tell me how to include header?