android - Text color in TextViews of ListView setted by selector works only in "normal" state -


I create ListView and my own listAdapter I use simple_list_item_2 I want to change the color of the text for each state below The code for dark.xml is:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Selector xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item Android: state_choose = "true" Android: color = "@color / selected text" /> & lt; Item android: state_focused = "true" android: color = "@ color / selectedTextListColor" /> & Lt; Item Android: stat_press = "true" Android: color = "@color / selected text" /> & lt; Item Android: Color = "@color / text list collar" /> & Lt; / Selector & gt;  

Next when I try to set that functionality, it is a part of code I think is a problem.

  Arrayadapter & lt; Element & gt; Adapter = new array adapter & lt; Element & gt; (E.g., android.R.layout.simple_list_item_2, LyricsArere) {@ Override Public View getView (integer status, see convertview view, ViewGroup parent) {TwoLineListItem line; If (convertView == faucet) {layout infletter inflater = (LayoutInflater) getApplicationContext () GetSystemService (References LAOUT_INFLATER_SERVICE); Line = (two lit. lit.) inflater.inflate (Android R.Lt.simple_l_l_i_times_2, empty); } And {line = (two linklist items) Convertview; } Element song = songr [status]; String data = song.text (); Int dashIndex = data.indexOf ("-"); TextViewText2 = Row ;getText2 (); Text2.setText (data.substring (0, dashIndex-1) .trim ()); Text2.setTextSize (12.0f); Text2.setPadding (10, text2.getPaddingTop (), text2.getPaddingRight (), text2.getPaddingBottom ()); Textview text1 = line.gettext1 (); Text1.setText (data.substring (dashIndex +1) .trim ()); Text1.setTextSize (18.0f); Text1.setPadding (10, text1.getPaddingTop (), text1.getPaddingRight (), text1.getPaddingBottom ()); Text1.setTextColor (.getResources () getColor (R.color.dark)); Return line; }};  

It still works like this, that the color of the text is red and does not change on the press. Can you tell it correctly? Note on line

  text1.setTextColor (getResources (). GetColor (R.color.dark));  

I think my mistake is.

  text1.setTextColor (.getResources () getColorStateList (R.color.dark));  

It was my problem now it works great.


Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -