0

我有以下

主.xml:

...
 <include
                    android:id="@+id/msg"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="3.5dp"
                    android:layout_weight="2"
                    layout="@layout/view_msg" />
..

view_msg.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" >

    <RelativeLayout
        android:id="@+id/relLayoutIcon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/view_img"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/icon" >
        </ImageView>

        <RelativeLayout
            android:id="@+id/relLayouttest"
            android:layout_width="40dip"
            android:layout_height="40dip"
            android:layout_centerHorizontal="true" >

            <RelativeLayout
                android:id="@+id/relLayouttess"
                android:layout_width="wrap_content"
                android:layout_height="22dip"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:gravity="center" >

                <TextView
                    android:id="@+id/txtViewtess"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="234"/>
            </RelativeLayout>
        </RelativeLayout>
    </RelativeLayout>

</LinearLayout>

Main.java //扩展 Activity{ ..

Test.setImageButton(this,
                R.id.msg,
                R.drawable.tess, Test.TAG_MESSAGES,
                mOnDialerClick);

Test.java //是一个简单的java类

public static  void setImageButton(Activity parent, int viewId,
            int imageId, int tag, View.OnClickListener listener) {

        View view = parent.findViewById(viewId);
        view.setTag(tag);
        view.setOnClickListener(listener);
        ((ImageView) view.findViewById(R.id.view_img)).setImageResource(imageId);

        RelativeLayout relLayouttess =((RelativeLayout)view.findViewById(R.id.relLayouttess));

        TextView txtViewtess = ((TextView)view.findViewById(R.id.txtViewtess));

        relLayouttess
                .setBackgroundResource(R.drawable.redbackground);
                txtViewNotifications.setVisibility(View.GONE);

    }

relLayouttess和txtViewtess都是NULL_ 为什么?我究竟做错了什么?

4

1 回答 1

0

你不需要寻找R.id.msg。可以直接找R.id.relLayoutIcon

View view = parent.findViewById(viewId);

viewId 在哪里R.id.relLayoutIcon

于 2013-05-13T12:24:00.973 回答