Android adding footer to ListView addFooterView()? Android adding footer to ListView addFooterView()? xml xml

Android adding footer to ListView addFooterView()?


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.


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.


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