I was trying the following code and was getting an error because there is no such constructor defined.
View v = new View(findViewById(R.id.divider));
Is there any simple way to copy a view into another?
Apparently you cannot clone views as stated by these answers:
How do I clone a View?
How to create Clone-Duplicate View?
If you inflated the first view from XML the way to go seems to be inflating the second view from XML, too.
To inflate your view from XML put it into an extra layout file, e.g. "textview.xml"
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" />
Then, inflate it from XML in your onCreate():
View view = LayoutInflater.from(this).inflate(R.layout.textview, null); myLayout.addView(view);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With