@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_listview, container, false); listview = (VerticalListView) rootView.findViewById(R.id.listView); TextView textView1 = new TextView(getActivity()); textView1.setText("header1"); textView1.setGravity(Gravity.CENTER); textView1.setTextColor(Color.WHITE); textView1.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)); textView1.setBackgroundColor(Color.GRAY); TextView textView2 = new TextView(getActivity()); textView2.setText("header2"); textView2.setGravity(Gravity.CENTER); textView2.setTextColor(Color.WHITE); textView2.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)); textView2.setBackgroundColor(Color.DKGRAY); TextView textView3 = new TextView(getActivity()); textView3.setText("footer1"); textView3.setGravity(Gravity.CENTER); textView3.setTextColor(Color.WHITE); textView3.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)); textView3.setBackgroundColor(Color.GRAY); listview.addHeaderView(textView1); listview.addHeaderView(textView2); listview.addFooterView(textView3); listview.setAdapter(new MyAdapter()); return rootView; }