android


Replaced views in LinearLayout programmatically


I have layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#535353">
<TextView
android:id="#+id/promo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_weight="1"
/>
</LinearLayout>
and I want to replace promo and title. Set first title, then promo.
I use this snippet.
public class AdView extends LinearLayout{
TextView promo;
public AdView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
LayoutInflater.from(getContext()).inflate(R.layout.view, this);
promo = (TextView) findViewById(R.id.promo);
title = (TextView) findViewById(R.id.title);
}
private void changePosition() {
removeView(promo);
addView(promo);
}
But, I get error: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
So, could you help me? How can I do this?

Related Links

Multiple colors in Toolbar title?
Intent overlap the dialog box?
Calling a Fragment Method in an Activity causes a Null Pointer Exception
How can obfuscate Sqlite Database in android
Snackbar Not working on API 17
How can I edit the header in a blank activity?
How do i access local area code in Android from locale?
Image from Android to PC
Charles Proxy + Android HTTPS
ScaleGestureDetector and GestureDetector in same view
Is there a performance impact on changing color of vector drawables programmatically?
Android web view does not load specific url
Attempt to invoke virtual method 'void android.widget.CompoundButton.setOnCheckedChangeListener on a null object reference on TabLayout [duplicate]
Retrieve all data from mysql database and display in listview android
Native Activity, GLES2.0: Uploading pixel array to screen
Get runtime Permissions in FirebaseInstanceIDService

Categories

HOME
algorithm
codenvy
dns
android-studio-2.2
character-encoding
oracle-apex-5
socket.io
spring-data-mongodb
onclick
augeas
windows-ce
mautic
mxgraph
xcodebuild
coin3d
charles
kendo-mobile
event-store
jboss6.x
siri
appirater
underscore.js
8051
bringtofront
subclass
carrierwave
vex
cart
quickfixj
angularjs-material
mailkit
alphabetical
wurfl
metawidget
unordered-map
plaintext
vaadin-elements
ntvs
opennms
magento-2.0.7
linter
posixct
arq
magic-draw
aquamacs
appdomain
backbone-collections
libjpeg
angular2-testing
builtins
reporting-services-2012
neon
turbo-prolog
fuzzywuzzy
fink
nio2
np-spring
state-restoration
ons-api
rubaxa-sortable
batik
atoi
graphics2d
fail2ban
openbabel
beatsmusic
android-vibration
crowd
administration
rmysql
cuba
verold
reflector
tinyxml
vsx
model-driven-development
script#
nebula
process-explorer
css-reset
virtual-pc
redis-py
extreme-programming
mkv
httponly
clrstoredprocedure
cdonts
socketserver
drupal-fivestar
pos-for-.net
duplex
tui
information-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App