Duplicate a view programmatically from an already existing view

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);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)