How to set text of a view defined in the Main Activity (no XML)
<p>I have a textView that is first created in the Main Activity onCreate file. Like this </p>

<pre><code>Button btn = new Button();
</code></pre>

<p>And then I set some attributes of it like an Id and some LayoutParams</p>

<pre><code>btn.setText("Button");
btw.setId("btn");
btn.setLayoutParams(new ViewGroup.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT));
</code></pre>

<p>So my question is how can I access this Id within the same file to change the text of the button. Like </p>

<pre><code>findViewById(R.id.btn);
</code></pre>

<p>Except when I do this I get an error. I am assuming since this is not defined within the XML. </p>

<p>EDIT: I cannot pre define these buttons in xml as they are generated based on other factors of the program. </p>

<p>Thank you.</p>