LoginSignup
2
2

More than 5 years have passed since last update.

ListFragmentをFragmentTabHostで管理する際にタブ切り替えでFooterViewが消える現象の対処法

Last updated at Posted at 2014-12-03

ListFragmentでaddfooterview()をしてFragmentTabHostでタブ切り替えして、addfooterview()をしたListFragmentのViewに戻るとaddfooterviewしたViewが消えている現象の対処法として、まずonCreate()などでフッターに入れたいViewを生成し、メンバ変数で保持する。

ListFragment.java
//リストフラグメントからListViewを取得
_listview = getListView();

__footer = getActivity().getLayoutInflater().inflate(R.layout.time_line_list_footer_layout, null);
_btn = (Button)_footer.findViewById(R.id.add);

@Override
public void onResume()
{
    super.onResume();
    if(_listview.getFooterViewsCount() == 0)
    {
        _listview.addFooterView(_footer);
    }
}

getFooterViewsCount()でgetFooterViewsCountが0だったら(_footer)が存在しなかったらaddFooterView(_footer)をする。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2