layout - Android TableRow background -


I have a problem with the tablero, which I dynamically add.

  Private Zero addRow (String Body) {Layout Infographic Inflator = (Layout Inflator) getSystemService (Reference. LAOUT_INFLATER_SERVICE); Tableline line = (tabler) inflater.inflate (r.layout.cimetro, empty); TextView name = (TextView) line.findbackstart (R.id.customName); Name.setText (body); Row.setOnLongClickListener (this); }   

I would like to change the color on this line to onClick and onLongClick .

The code is customrow.xml file:

  & lt; TableRow xmlns: Android = "http://schemas.android.com/apk/res/android" Android: id = "@ + id / tableRow1" Android: layout_gravity = "center" Android: layout_height = "wrap_content" Android: layout_width = "Fill_parent" android: gravity = "center_vertical" android: onClick = "showOnClick" & gt; & Lt; TextView Android: Android: textSize = "25px" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "textview" Android: layout_weight = "5" & gt; ; & Lt; / TextView & gt; & Lt; / TableRow & gt; I have tried to use  android: background = "@ drawable / clickedbackground" , but it is not working.  

The code is in the clickedbackground.xml file:

  & 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_selected = "true" android: state_focused = "false" Android: state_pressed = "false" android: drawable = "@ android: color / transparent" /> & Lt; Item Android: state_selected = "false" Android: state_focused = "false" Android: state_pressed = "false" Android: drawable = "@Android: Color / transparent" /> & Lt; Item Android: state_pressed = "true" android: drawable = "@color / custom" /> & Lt; Item android: state_focused = "true" Android: state_selected = "true" android: state_pressed = "false" android: drawable = "@color / custom" /> & Lt; / Selector & gt; Anyone knows what I'm doing wrong (color / custom is defined in another XML which works)?  

Thank you

For the named line you have tablerow You are creating the object and you also have the clickedbackground.xml file. Use the code below in the addRow method.

row.setBackgroundResource (R.drawable.clickedbackground);

I think that solves your problem.

Comments