1

我正在View通过膨胀 xml 布局来制作:

    LayoutInflater inflater = (LayoutInflater) getBaseContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(com.example.R.layout.aaa, null);

在 aaa.xml 我有一个RelativeLayout本身包含 aTextView和 a 的Button。现在我怎样才能访问那个TextView视图对象?

4

1 回答 1

1

首先,您尝试访问的 TextView 必须有一个 id(例如 @android:id="@+id/yourTxtId"),然后从您的 rootView 开始,在您的情况下,您实际上是在夸大您所要做的一切是:

View view=inflater.inflate(com.example.R.layout.aaa, null);
TextView txt = (TextView)view.findViewById(R.id.yourTxtId);
//And here you have the reference...

问候!

于 2013-09-11T17:30:35.780 回答