Perhaps your mistake in this method
runOnUiThread(new Runnable() { @Override public void run() { LinearLayout layout = (LinearLayout) findViewById(R.id.ololo); TextView txt = new TextView(getApplicationContext()); txt.setText("123123123"); LinearLayout newLayout = new LinearLayout(getApplicationContext()); newLayout.addView(txt,0); }
First you inflate LinearLayout
with the markup:
LinearLayout layout = (LinearLayout) findViewById(R.id.ololo);
Then create a TexView
TextView txt = new TextView(getApplicationContext());
And then you create an incomprehensible LinearLayout
LinearLayout newLayout = new LinearLayout(getApplicationContext());
and put a TexView
in it
newLayout.addView(txt,0);
In this case, if after that you nowhere add newLayout
to your markup - it turns out that you simply add your TextView - nowhere.
Try replacing the code with this one, it can help:
@Override public void run() { LinearLayout layout = (LinearLayout) findViewById(R.id.ololo); TextView txt = new TextView(getApplicationContext()); txt.setText("123123123"); layout.addView(txt,0); }
UPD:
public class TestActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_activity); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ololo); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.weight = 0.01f; TextView textView = new TextView(this); textView.setText("Custom text"); linearLayout.addView(textView,params); } }
Here in this form, using your markup, add a new `TextView ', how to make it appear so that you normally need to think, I would change the layout.
