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

Issue fetching data in SQLite
Android: Update ListView from EditText
Fix My Firebase database Chat Application
Setting LinearLayout in different screen size
Android XML| Understanding the pathData syntax
Can't run exec(“su”) on a rooted Android Marshmallow device, other commands run fine
Picasso only loading single image but the size is 20
Unable to restrict number of records to be fetched to client in firebase Android
Save Markers on Android Map App
Adding individual view animations for RecyclerView
Retrieve Data from Firebase Database and populate Listview
How to close popup window with from menu item in Android [duplicate]
Glide error when loading a recyclerView “You must pass in a non null View”
AlarmManager.setRepeating not working when backgorund
Disabling quick settings and notifications bar in Lollipop
RxJava onBackpressureBuffer not emitting items

Categories

HOME
android
shell
microsoftgraph
paraview
ggplot2
wakanda
redux-form
camera
google-cloud-functions
static-site
vsm
modal-dialog
g++
google-chrome-app
siddhi
spring-social
altera
entitymanager
firefox-addon
intershop
topology
replication
sar
microsoft-ocr
systemtime
short-url
monit
siri
progress-bar
fractions
gitlab-api
angularjs-material
fossil
least-squares
processwire
salesforce-communities
jpad
node-mssql
ssrs-2014
knime
berkeley-db-je
signal-strength
jboss-4.2.x
libgphoto2
gitlist
reportservice2010
cpu-cache
branch-prediction
donations
omxplayer
custom-lists
actor-platform
tooleap
respondcms
nservicebus5
nss
php-socket
hadoop-partitioning
blitline
mobiledoc-kit
video-player
android-launcher
page.js
skspritenode
jsvc
alloy-ui
android-broadcast
deform
post-commit-hook
easyrtc
linkedin-jsapi
encryption-asymmetric
lnk
cancellation
matrix-inverse
android-framework
conditionaltagsupport
ora-06550
scriptaculous
embedded-fonts
scringo
traceability
http-status-code-410
preload
saleslogix
subgraph
paginator
infobright
jquery-tools
landscape-portrait
android-holo-everywhere
google-floodlight
unattended-processing
msr
svk
dot-emacs
eclipse-marketplace
hbm2java
nstokenfield
spread
strtod
application-planning
lemmatization
wcf-proxy
leader
image-capture

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