Answer the question
In order to leave comments, you need to log in
How to programmatically change the parent of a component, for example, a button, from LinearLayout1 to LinearLayout2?
There is a program with two LinearLayout1 and LinearLayout2
there is a button event. It is necessary for the button to change the parent of LinearLayout1 to LinearLayout2 on an event.
It is not advisable to recreate the button. I would like to transfer the current one.
Answer the question
In order to leave comments, you need to log in
It is possible to get all the button settings with the get command, delete it programmatically, and programmatically, knowing the settings, create a new button in the desired layout. It would be easier to make this button a fragment and put and remove it where necessary. You can write a button in a method and, depending on the parameters, call a method that will decide which layout to put the button on. LayoutInflater is a class that can create a View element from the contents of a layout file. The method that does this is called inflate. There are several implementations of this method with different parameters. But they all use each other and the result of their execution is the same - View. More here https://developer.android.com/reference/android/vi...
I thought maybe it's still possible TextView textView2 = new TextView(); textView2 = textVew1; Here we must delete that button, and do it myLayout.add(textView2); It is necessary to delete so that an error with the same id does not occur, perhaps this is the best solution
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question