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

Calling second activity with startActivity causing crash
ViewPager in a NestedScrollView
Debugging application gives me a red line
android: is it possible to keep a title above the spinner on actionbar
Google Analytics causes error on Cordova app only after I sign my APK
Is it possible to get an icon, text or both item in the list on recyclerview and pass it to another activity using intent
Android - Application crashes with Out Of Memory when selecting very large image [duplicate]
Should I replace Android Activities by Fragments?
How to read gradle file properties from Android app programatically
AsyncTask, network operations and timeouts
Using StrictMode in app production phase
VideoView inside Fragment
How to disable devices supported from Android Studio
Container, Image and Text: How to get it working together?
Dagger class could not be bound with key
unity touch control with UI image

Categories

HOME
service-worker
batch-file
kentico
telegram
phpmyadmin
formal-languages
requirements
shiro
access
telegram-bot
odoo-8
rcloud
datastage
tput
frequency-distribution
linear-algebra
job-scheduling
video-editing
google-container-registry
charles
database-connection
babel
imagemap
r-mice
monit
android-sharedpreferences
memory-address
code-snippets
instantiation
sendbird
dynamic-jasper
installscript
latitude-longitude
tex
typesafe-config
resolution
doc
levenshtein-distance
congestion-control
show-hide
x++
dynamic-linq
jquery-ui-draggable
facebook-pixel
configurationmanager
scalding
excel-dna
sundials
ampps
structuremap4
android-instrumentation
change-tracking
pure-css
qtplugin
nikeplus-api
rspec2
cifilter
nservicebus5
blitline
toast
directdraw
morton-number
batik
iced-coffeescript
wso2greg
ansi
omnifaces
xmltype
openbabel
apache-spark-1.3
cosine-similarity
webmatrix-3
administration
sql-scripts
raygun
tinyxml
renderer
rfc5322
hibernate-entitymanager
pclzip
fb.ui
qtconcurrent
entity-attribute-value
android-holo-everywhere
automationelement
exponentiation
clrstoredprocedure
svk
luajava
commerceserver2007
silent
drupal-fivestar
alsb
product-management
ifilter
pbcopy
blind

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