Objective
This problem in the previous to do a box project encountered, and recently encountered, using the GridView encountered a very wonderful problem, here record share.
StatementWelcome reprint, but please keep the original source of the article:)Blog Park: http://www.cnblogs.comFarmer Uncle: Http://over140.cnblogs.com
Body
First, the question
1.1 First Look at the problem code:
@Override
PublicView GetView (intPosition, View Convertview, ViewGroup parent) {
if(Convertview = =NULL) {
Convertview = Layoutinflater.from (Getactivity ()). Inflate (R.layout.fragment_feed_grid_item, parent,false);
Convertview.findviewbyid (R.id.avatar). Setonclicklistener (NewView.onclicklistener () {
@Override
PublicvoidOnClick (View v) {
//startactivity
}
});
}
Convertview.setlayoutparams (Newgridview.layoutparams (MWINDOWWIDTH/3, MWIDOWWIDTH/3));
//other Code
returnConvertview;
}
The purpose of the code is to dynamically set the size of the item within the GridView according to the width of the screen, which is naturally written.
1.2 Specific symptoms
1.2.1 The first item of the ImageView display is not complete, always show half, the other item no problem, such as how to set up is useless
1.2.2 The Click event set in the first item does not work, but a gentle scrolling of the Click event immediately takes effect.
Ii. Solutions
@Override
PublicView GetView (intPosition, View Convertview, ViewGroup parent) {
if(Convertview = =NULL) {
Convertview = Layoutinflater.from (Getactivity ()). Inflate (R.layout.fragment_feed_grid_item, parent,false);
Convertview.setlayoutparams (Newgridview.layoutparams (MWINDOWWIDTH/3, MWINDOWWIDTH/3));
Convertview.findviewbyid (R.id.user_avatar). Setonclicklistener (NewView.onclicklistener () {
@Override
Public voidOnClick (View v) {
//startactivity
}
});
}
//other Code
returnConvertview;
}
As above.
Iii. related articles
Why is changing where layout parameters am set solving my "Onclicklistener not working for first item in GridView" issue?
End
The blog is becoming obsolete, still need to write frequently.
"Android Troubleshooter" GridView dynamic setting item's wide height causes the first item to not respond or show an unhealthy problem