Android ListActivity - fixed header and footer

后端 未结 3 1731
时光说笑
时光说笑 2021-01-02 21:58

Is it possible to set header and footer at ListActivity to be fixed at the top and the bottom, so only the content (list) is scrolling, not also header and footer?

I

3条回答
  •  臣服心动
    2021-01-02 22:14

    You can do it this way given below:

        //your adapter for listview
        mAdapter = new ToDoListAdapter(getApplicationContext());
    
        // Put divider between ToDoItems and FooterView
        getListView().setFooterDividersEnabled(true);
    
        // TODO - Inflate footerView for footer_view.xml file
        LayoutInflater layoutInflater = getLayoutInflater();
    
        //text view or whatever you have for your footer
        TextView footerView = null;
        footerView=(TextView)layoutInflater.inflate(R.layout.footer_view,null);
    
        // TODO - Add footerView to ListView
    
        getListView().addFooterView(footerView);
        getListView().setAdapter(mAdapter);
    

    This is inside of your onCreate() method. It worked for me. give comments if you find any bugs here

提交回复
热议问题