I have a view with a TextView and a Custom View laid out in a RelativeLayout. I am inflating the xml and I see both the TextView and CustomView rendered. Now I want to modify the text in the TextView depending on the actions of the user. How can I access the TextView from the view? I thought the following will work but I got a null –
mDisplay = (TextView)this.findViewById(R.id.displayBuffer);
The above works from inside the Activity but I really want to access it and modify it from the View.
EDIT: I did not post code because it might distract from the question. I am thinking accessing/modifying the TextView from inside a View should be a generic problem and nothing to do with my layout in specific. Having said that here is the layout —
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="ASDFASDF"
android:textColor="#ffFFFFFF"
android:layout_gravity="center_vertical"
android:paddingBottom="9dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="2dip"/>
<com.ac.gui.CustomView
android:layout_below="@+id/question"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Thanks,
– P
Assuming the two Views are in the same layout hierarchy:
If you look at the docs,
findViewByIdsearches its child views, so you should go up the hierarchy before searching.