Skip to content Skip to sidebar Skip to footer

Android: Edit Textview Defined In Xml

I have been sitting for at least 4 hours trying to solve this problem. To understand this there are 3 files you need to know about: eggCatcher.java which extends Activity, this cla

Solution 1:

I think you should get the parent view and then from there on you can use findViewById() (are you sure you can't just use that method anyway since SurfaceView is a subclass of View and inherits findViewById() from it?).

For using the parent you do something like:

ViewParentvp= eggCatcherView.getParent();
FrameLayoutfl= (FrameLayout) vp;
TextViewtx= (TextView) fl.findViewById(R.id.bonus);

Of course you need to check if the ViewParent is indeed an instance of FrameLayout.

Solution 2:

I found this the best way:

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:id="@+id/test"/>
</LinearLayout>

TextView test = (TextView) findViewById(R.id.test);
test.setText("test");

Solution 3:

If I understand correctly, you want to access the views in the surrounding activity? That seems like poor architecture. I think it would be better to either pass a callback to the EggCatcherView that can trigger methods in the Activity which in turn operate on the TextViews or fire some kind of events upwards.

Post a Comment for "Android: Edit Textview Defined In Xml"