[Difficult to handle Android problems] Gallery default and landscape screen switching selection status problems (2.3, 2.3 System)

Source: Internet
Author: User

Preface

Gallery's Item uses an ImageView + TextView and sets selector for it. The Item status will not change when setSelection is used and the screen is switched horizontally and vertically, this currently exists in systems 2.2 and 2.3. a later version, such as 4.0, does not exist.


Statement
Welcome to repost, but please keep the original source of the article :) blog Park: http://www.cnblogs.com

Farmer's uncle: http://over140.cnblogs.com

 

Body

1. Step 1: Solve the ImageView status problem

Set for ImageView

Android: focusableInTouchMode = "true"

Note that TextView settings for the same attribute are not used.

 

Step 2: manually control the text to set different colors based on different States

2.1 notify Gallery of Adapter data update notifyDataSetChanged in onConfigurationChanged

2.2 notify Gallery's Adapter data update notifyDataSetChanged in onItemSelected of Gallery

2.3 modify the text color based on the selected index in getView of the Gallery Adapter.

If (position = mGallery. getSelectedItemPosition ()){
Title. setTextColor (COLOR_NAV_SELECTED );
} Else
Title. setTextColor (COLOR_NAV_NORMAL );

COLOR_NAV_SELECTED and COLOR_NAV_NORMAL are the selected and unselected colors respectively.

 

 

End

Note: this problem does not exist when you manually slide the Gallery. It exists when you change the Gallery selected item through setSelection and does not exist in the later version.

 

 

Related Article

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.