1

編集テキストと画像ビューでテーブルを動的に埋めています。表の行が押されたときに表の行全体が強調表示されるようにします。

コード:

    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);



}

Drawable/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

よろしくお願いします。具体的にお願いします

4

0 に答える 0