Home create textview dynamically and let it show the value of a variable
Reply: 0

create textview dynamically and let it show the value of a variable

user1727 Published in May 21, 2018, 12:49 pm

I'm new to Android and I can't solve my Problem on my own or find an accurate answer to my problem.

So what i want to accomplish is this: every time I click on a Button it should create a new TextView and this newly created TextView shall show the value of an EditText at the time I click that Button.

So for example: if I write "This" in the EditText and click on the Button it should create a TextView showing "This". And if I then write "works" in the same EditText and press the Button it should create a second TextView showing "works".

So let me show you what I tried:

protected void onCreate(Bundle savedInstanceState) {

    Button b = (Button)findViewById(R.id.erstellButton);
    ll = (LinearLayout)findViewById(R.id.LL);
    layoutParams = new LinearLayout.LayoutParams
            (layoutParams.WRAP_CONTENT, layoutParams.WRAP_CONTENT);

    b.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v) {
            et = (EditText) findViewById(R.id.editText3);
            TextView view = new TextView(AusgabeActivity.this);
            ll.addView(view, layoutParams);
            String plsJustWork = et.getText().toString();
            view.setText(++i+"test" +plsJustWork);


Right now if I'm using this code a new TextView is created every time I click the Button, but it only shows "1test" and the next time I click the Button it shows "2test". So the value of the EditText (editText3 / et) is not shown.

I would appreciate any help.

Best regards, Yannic

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.366009 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO