I have a custom textview class with this code:
public CustomTextView extends TextView {
public CustomTextView(Context c, AttributeSet a) {
super(c, a);
TextView tv = (TextView) findViewById(R.id.myTv);
String str = tv.getText().toString();
setText(str);
}
}
And my main.xml contains this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myTv"
android:text="Unkown" />
<com.test.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="100.0sp" />
What I want to do is I want to get the string value of the TextView(with ID of myTv) and set the text of my CustomTextView same as the TextView. Something like TextView = CustomTextView.
The string value of myTv is changed by a sharedpreferences so everytime the text changes, the custom text also will change.
My problem is how to do this correctly?