Updating Android UI from custom view
<p>I'm new to Android development, and still having difficulties comprehending how the framework works. I try to write a simple game to get some experience and I'd like to ask for some help with the below.
In my main Activity, I have a few TextViews to show various data from my game, and under those I have a custom View called AnimatedView that has the canvas where I draw my objects for the game itself. Based on the objects on the Canvas, I'd like to update the TextViews to show e.g. number of object, what level the player is at, etc.</p>

<p>The problem is, even though I can get the TextView object with the below code, when I call textView.setText(...), nothing changes on the UI.</p>

<p>The below is a simplified version of my real code, to demonstrate the problem:</p>

<p><strong><em>activity_main.xml</em></strong></p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    ...
    tools:context="com.danielsh.test.teststuff.MainActivity"
    android:orientation="vertical"&gt;

    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myTextView"
        android:text="Change this!" /&gt;

    &lt;com.danielsh.test.teststuff.AnimatedView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/animView" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p><strong><em>MainActivity.java</em></strong></p>

<pre><code>public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
</code></pre>

<p><strong><em>AnimatedView.java</em></strong></p>

<pre><code>public class AnimatedView extends View {
    public AnimatedView(Context context, AttributeSet attrs) {
        super(context, attrs);

        final Handler uiHandler = new Handler();
        final Runnable runnable = new Runnable() {
            public void run() {
                LayoutInflater inflater = LayoutInflater.from(getContext());
                LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.activity_main, null, false);
                TextView textView = (TextView) layout.findViewById(R.id.myTextView);
                textView.setText("" + (System.currentTimeMillis() / 1000));
                textView.invalidate();
            }
        };

        uiHandler.postDelayed(runnable, 1000);
    }
}
</code></pre>

<p>I assume that I'm not working with the actual TextView object that's visible on the UI, but not sure what'd be the correct way of doing that.</p>

<p>Any help or pointer to an existing post that deals with the same problem would be much appreciated.</p>