0

为了清楚起见,我重写了这个问题:

我有一个 ListView 和一个 FooterView,页脚内有一个刷新按钮。

我在活动级别保留对所有这些的引用

  ListView myListView;
  View     footerView;
  Button   refreshBtn;

 onCreate(Bundle)
 {
          footerView = inflate footer view etc;
          refreshBtn = footerView.findViewById(R.id.refresh_btn);
          refreshBtn.setOnClickListener(this);
          myListView.addFooter(footerView);
 }

  onClick()
 {
     // refresh clicked.  Don't show FooterView anymore unless its needed again
      myListView.removeView(footerView)  //

 }

 onRefresthResult()
 {
    // looks like we need to try refresh again.  So lets add the refresh footer back in.
    // THIS DOES NOT WORK. CLICKING refreshBtn does NOTHING.
     myListView.addFooter(footerView);
     resetListAdapter();


     // Now refresh button does NOTHING. unless we do THIS below instead.

     // THIS DOES WORK, BUT WHY?
     footerView = inflate footer view.   (Why does this need to be done again. footerView was not null both it and the refreshBtn seemed to have valid values).
     refreshBtn = footerView.findViewById(R.id.refresh_btn);
     refreshBtn.setOnClickListener(this);

     // Note footerView reference was always valid and resetting onClick 
        without reinflating did not work.

 }

我唯一的理论是,当您删除视图时,它会以某种方式被标记,因此必须重新添加页脚视图的新实例?

4

1 回答 1

1

嘿,你可以让你的页脚在 onclick 函数中不可见,比如

footerView.setVisibility(View.INVISIBLE);
于 2013-10-25T17:05:38.240 回答