New for Android: dynamically changing views

I am trying to learn how to create Android applications.

The first simple application to become a component of the larger application that I hope to build is to have a button on the screen where, when clicked, it adds something new to the view.

For instance:

Imagine a layout that has only a button:

[Create!]

When this button is pressed, a new line appears in the view, added to it:

[Create!]
A Something!

Subsequent clicks add more lines

[Create!]
A Something!
A Something!

Etc.

I made a LinearLayout and put a button in it, and attached a click listener to it. This all works great. I can’t figure out how to get the LinearLayout handle in the onClick function, with which I will add () a new TextView that says "A Something!"

? ? !

+3
2

, . ListView SimpleArrayAdapter. , . Google , (, Notepad). , Android, , .

+1

, .

LinearLayout id.

< LinearLayout
XMLNS: = "http://schemas.android.com/apk/res/android"
Android: ID = "@+ /namehere "
... >

findViewById, .

LinearLayout ll = (LinearLayout) findViewById (R.id.namehere);

ll.addView(...);

0

Source: https://habr.com/ru/post/1750615/


All Articles