Skip to content

Instantly share code, notes, and snippets.

Created September 25, 2014 20:49
Show Gist options
  • Save ruckus/df82ff441994580ebac2 to your computer and use it in GitHub Desktop.
Save ruckus/df82ff441994580ebac2 to your computer and use it in GitHub Desktop.
Example of using a ViewPager as a Header in a ListView. We need to explicitly set the layout params of the Header view because its not known at initialization time, in my case I am asynchronously loading images into the ViewPager.
public class ProductDetailActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
final DisplayMetrics displayMetrics = new DisplayMetrics();
final int width = displayMetrics.widthPixels;
mListView = (ListView)findViewById(;
// Initialize the header view
View headerView = (LinearLayout)getLayoutInflater().inflate(R.layout.product_detail_header_row, null);
mFeaturedImagePager = (ViewPager)headerView.findViewById(;
mFeaturedImageAdapter = new FeaturedImagesPagerAdapter(getSupportFragmentManager(), mFeaturedImageUrls.size());
mListView.addHeaderView(headerView, null, false);
// The crucial part
AbsListView.LayoutParams headerViewParams = new AbsListView.LayoutParams(width, 400);
Copy link

How you solved the problem?
E/InputEventReceiver(30633): Exception dispatching input event.
When I scroller down and up the listview, throws this exception.

Copy link

Igorpi25 commented Feb 5, 2015

Thank you! It solved my problem with GridView inside ListView's header.
1). I noticed that such problem will appear every time when the size(width/height) of layout/widget inside ListView's header is undefined when ListView inittializes itself. Be careful when use inside a header widgets with the custom background drawable.
2). If you have excess area inside header - try paint all layouts and widget (ALL WIDGETS AND LAYOUTS!) inside header in different colors. The cause of excess area might be unexpected widget from completely unexpected place (multilined EditText in my case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment