1

how can i add an header on RecyclerView like ListView with addHeaderView(View v) method and have same behavior. My current code using ListView that i want change to RecyclerView:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getActivity() == null) {
        return;
    }

    ListView listView = (ListView)getView().findViewById(R.id.list_view);
    if (listView != null) {            
        listView.setOnScrollListener(this);
        listView.setOnItemClickListener(this);            
        // Add Header
        View header = getListHeader();
        if (header != null) {
            listView.addHeaderView(header, null, false);
        }           
        // set Adapter
        adapter = getListAdapter();
        if (adapter != null) {
            listView.setAdapter(adapter);
        }
    }
}

Thanks all.

dledo
  • 44
  • 3
  • There is no default method (like addHeaderView() for the ListView ) doing that, but you can do some workaround in your adapter. Something like this http://stackoverflow.com/a/26573338/4224337 – Rami Jan 06 '15 at 11:05
  • I'm trying avoid that solution,keeping adapter independently of added headers. But probably i will use that solution. Thanks a lot. – dledo Jan 06 '15 at 12:32

0 Answers0