我正在使用编辑文本和图像视图动态填充表格。我希望在按下表格行时突出显示整个表格行:
代码:
public void display(News news)
{
LinearLayout.LayoutParams LLParams=new LinearLayout.LayoutParams (LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,1.0f);
TableRow.LayoutParams tableRowParams=new TableRow.LayoutParams (TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT,1.0f);
TableRow TR= new TableRow(this);
TR.setClickable(true);
TR.setFocusable(true);
TR.setFocusableInTouchMode(true);
TR.setBackgroundResource(drawable.table1);//set background according to selector
LinearLayout LL= new LinearLayout(this);
TR.setLayoutParams(tableRowParams);
Table1.addView(TR);
TR.addView(LL, new TableRow.LayoutParams (TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT,1.0f));
//Table Row contains EditText and ImageView
EditText editText1 =new EditText(this);
ImageView imgview=new ImageView( this);
LL.addView(imgview, new LinearLayout.LayoutParams (LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,4.0f));
LL.addView(editText1, new LinearLayout.LayoutParams (LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,1f));
editText1.setText(news.getTitle()+"\n"+news.getSubtitle());
editText1.setKeyListener(null);
editText1.setTextColor(0xff000000);
editText1.setTextSize(15);
imgview.setImageDrawable(news.getDr());
imgview.setAdjustViewBounds(true);
imgview.setMaxHeight(50);
imgview.setMaxWidth(50);
}
可绘制/table.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ff00ff00"/>
<!-- pressed -->
<item android:state_focused="true" android:color="#ff00ff00"/>
<!-- focused -->
<item android:color="#00000000"/>
<!-- default -->
</selector>
我得到了这个例外:
10-10 07:02:10.058: E/AndroidRuntime(1879): android.content.res.Resources$NotFoundException: File res/drawable/table1.xml from drawable resource ID #0x7f02001f
我会很感激你的帮助。请具体