Android adding footer to ListView addFooterView()?

后端 未结 3 1400
时光取名叫无心
时光取名叫无心 2020-12-10 04:08

I have a ListView activity that needs a footer to the list of items so that you can click it and it would load more items into the list. The list is backed my an SimpleAdapt

相关标签:
3条回答
  • 2020-12-10 04:36
    View footerView = getLayoutInflater().inflate(R.layout.search_footer,
                mContentList, false);
        LongButton mSearchMoreBtn = (LongButton) footerView
                .findViewById(R.id.searchmore_btn);
        mSearchMoreBtn.setText(R.string.search_moreapp);//the button to add 
        mSearchMoreBtn.setBackgroundResource(R.drawable.btn_long_selector);
        mSearchMoreBtn.setOnClickListener(mSearchMoreBtnListener);
    
        footerView.setOnClickListener(mLoadMoreAppsListener);
        mContentList.addFooterView(footerView);  
    

    I have no idea that when I adding mSearchMoreBtn to ListView as footerView, it is wrong, instead, when I adding footerView to ListView, it just fine

    0 讨论(0)
  • 2020-12-10 04:42

    Alrighty Iv found a solution to my problem if i do this it works as intended:

    View view = mInflater.inflate(R.layout.list_load_more_row, null);
    
    TextView footer = (TextView) view.findViewById(R.id.loadMore);
    
    getListView().addFooterView(footer);
    
    setListAdapter(ListViewHelper.getAdapterForContentList(mContent, this));
    

    I'm guessing that since I put null in the inflater as the parent parameter, the view has not been added to the current content view and so mainActivity is unable to find it and now since I am explicitly using the parent view that is returned by the inflater to find the TextView it is working.

    0 讨论(0)
  • 2020-12-10 04:54

    as ognian stated in his comment above, loadMore is probably not found.

    you can see if this is the issue by changing your code to something like this:

    TextView footer = (TextView) findViewById(R.id.loadMore);
    if ( footer != null ) {
      getListView().addFooterView(footer);
      setListAdapter(ListViewHelper.getAdapterForContentList(mContent, this));
    } else {
      throw new NullPointerException("footer is null");
    }
    

    without seeing more of your code, it is hard to say what the actual cause is.

    0 讨论(0)
提交回复
热议问题