[Java for Android App Development] code_name:
Hi guys, I am new to android development and I'm having a little trouble working with a list in fragment.

This is what I'm trying to achieve:

------------------

frag 1

------------------

frag 2 <-- list is here

-----------------

frag 3

-----------------

The list displays 3 strings in one row. This is my fragment code: ( the CustomListViewAdapter is implemented in another file called CustomListViewAdapter.java)

public class ListActivity extends Fragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fm = getFragmentManager();
if (fm.findFragmentById(android.R.id.content) == null) {
DataListFragment list = new DataListFragment();
fm.beginTransaction().add(android.R.id.content, list).commit();
}
}

public static class DataListFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<List<Model>> {

CustomListViewAdapter mAdapter;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

System.out.println("DataListFragment.onActivityCreated");

// Initially there is no data
setEmptyText("No Data Here");

// Create an empty adapter we will use to display the loaded data.
mAdapter = new CustomListViewAdapter(getActivity());
setListAdapter(mAdapter);

// Start out with a progress indicator.
setListShown(false);
}

@Override
public Loader<List<Model>> onCreateLoader(int arg0, Bundle arg1) {
return new DataListLoader(getActivity());
}

}

public static class DataListLoader extends AsyncTaskLoader<List<Model>> {

List<Model> mModels;

public DataListLoader(Context context) {
super(context);
}

@Override
public List<Model> loadInBackground() {
System.out.println("DataListLoader.loadInBackground");

List<Model> entries = new ArrayList<Model>(5);
entries.add(new Model("1", "a","3:48"));
entries.add(new Model("2", "b","4:02"));
entries.add(new Model("3", "c","3:48"));
entries.add(new Model("4", "d","3:52"));
entries.add(new Model("5", "e","3:44"));

return entries;
}

@Override public void deliverResult(List<Model> listOfData) {
...
}
@Override protected void onStartLoading() {
...
}

protected void onReleaseResources(List<Model> apps) {}

}

The 3 fragments are added programmatically in the main activity. MainActivity.java

The problem I am facing is that once the code runs, this fragment 2 overlaps the fragment 1 (both are still visible) that was supposed to be above it. How do I resolve this issue? Please help me figure this out! I believe I'm doing something wrong while adding this fragment.

This is the mainactivity.java

public class MainActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

setContentView(R.layout.main_layout);

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.info_fragment, new InfoActivity());//frag 1
fragmentTransaction.add(R.id.list_fragment, new listActivity()); // frag 2
fragmentTransaction.add(R.id.controls_fragment, new ControlsActivity()); //frag 3
fragmentTransaction.commit();

}

}