Search code examples
androidandroid-layoutandroid-listviewandroid-listfragment

Android - why can I not add a footer view to the ListView of a ListFragment?


I previously had this code working no problem within a ListActivity, now I am refactoring to use ListFragment and the code compiles yet I see no button (footer)

Code:

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

    log("+ ON ACTIVITY CREATED +");

    listView = getListView();

    // Retrieve routines ArrayList from JSON
    routineList = FitnessApp.routineList;   

    routineList.add(new Routine("test routine"));

    adapter = new GeneralTemplateAdapter(routineList, getActivity().getLayoutInflater());

    listView.setAdapter(adapter);

    // Creating bottom button as a footer view
    Button bAddNew = (Button) getActivity().getLayoutInflater().inflate(R.layout.add_new_button, null);
    bAddNew.setText("Add Routine");

    listView = getListView();   // Get reference to ListActivities ListView
    listView.addFooterView(bAddNew);
}

Any ideas?

Cheers


Solution

  • Ah I was forgetting the simple fact you have to declare your headers and footers before you add an adapter