Android - 为什么我不能在ListFragment的ListView中添加页脚视图?

时间:2013-04-24 21:00:19

标签: android android-layout android-listview android-listfragment

我以前在ListActivity内使用此代码没有问题,现在我正在重构使用ListFragment并且代码编译但我看不到按钮(页脚)

代码:

@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);
}

有什么想法吗?

干杯

1 个答案:

答案 0 :(得分:4)

啊我忘记了在添加适配器之前必须声明页眉和页脚的简单事实