"Android Troubleshooter" GridView dynamic setting item's wide height causes the first item to not respond or show an unhealthy problem

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.