GridView - first item has no highlighted state

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

GridView - first item has no highlighted state

Postby Merdica » Fri Aug 09, 2013 10:24 am

Hello,

I want to fill a gridView with buttons. I use a common adapter which I give a list of objects. From these object I created my Buttons in the getView(). The buttons have two states, normal and pressed. Therefore I use a selector.xml.

Generally it works well. My Problem is now that for the first icon in the grid is no pressed state (highlighted state) is shown.

Maybe it has something to do with multiple calling of getView(). The first button is created twice. At the beginning and at the end. I don't change the items afterwards.

Maybe someone can help me, thanks
Merdica
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Jun 06, 2011 9:40 pm

Top

Re: GridView - first item has no highlighted state

Postby Merdica » Mon Aug 12, 2013 5:04 pm

It figured out that the problem is something else.
The layout for the grid cell is a image button. The bitmap for the image button is created from an selector.xml for 2 states: normal and pressed:
The icon is shown, but with a grey background color. Now, when I set the background transparent, the highlighted state of the first icon in the grid view is not shown. That happens every time i set a background attribute, no matter what color.

I found that problem in some other forums, but only with a solution for a local selector.xml. I can't do that because I get the files dynamically from my library projects.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. dashBoardButtonIcon.setBackgroundDrawable(dashboardIcon.getIcon());
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3.     <item android:drawable="@drawable/db_modul_icon_carfinder_pressed" android:state_pressed="true"/>
  4.     <item android:drawable="@drawable/db_modul_icon_carfinder"/>
  5. </selector>
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Any ideas?
Merdica
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Jun 06, 2011 9:40 pm

Re: GridView - first item has no highlighted state

Postby Merdica » Fri Aug 23, 2013 10:27 am

My solution/workaround:

Is used instead of a Button an ImageView and set the Selector with setBackgroundResource().
Then it works with background image, transparency and states.
Merdica
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Jun 06, 2011 9:40 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests