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

How can I get subtitle with video without srt file?
Add SOAP Header to Volley Request Android
Execute a method of a fragment from espresso
shrinkresource ,proguard etc in xamarin doesn't reduce my app size
Android - Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
Can an image be used in FloatingActionButton?
Pressing top back navigation how to show initial results ,when searchResults are in the same main Activity?
Fragment not displaying correctly on second click?
How to Use Dynamic Image(URL) form json in bitmap
How do I know whe the Webp/Gif animation is completed in Fresco
How can I keep my app backstack in the phone's memory
why application crashes when when using onConfigurationChanged function?
Service not started while booting
how can i call a String variale in a query?
Missing something with FCM Configuration
RecyclerView with GoogleMap in one element. Map not refreshing

Categories

HOME
facebook-oauth
design-patterns
codenvy
fpga
angular-formly
flex
components
vscode-extensions
google-cloud-functions
interpolation
title
fhir
angular-dart
openbugs
onedrive-api
flatpak
android-7.0-nougat
delphi-xe5
boost-icl
href
joptionpane
flask-sqlalchemy
interpreter
direct3d11
fable-f#
genexus-sd
comparable
nsurl
volatile
left-join
database-comparison
memory-address
sammy.js
vue-chartjs
slacktextviewcontroller
apns-php
metawidget
unordered-map
ogc
android-softkeyboard
glm-math
oracle-service-bus
placeholder
android-exoplayer
photos
clang++
strftime
libgphoto2
wcftestclient
reportservice2010
dbcontext
manova
dt
rackspace-cloud
google-photos
django-1.10
ampps
bootstrap-tags-input
redistributable
reporting-services-2012
dotnetnuke-7
watch-os-2
model-associations
hclust
embedding
cassia
mediametadataretriever
html-to-pdf
grass
exim4
qbxml
toran-proxy
flock
xvim
cgi-bin
nsurlsessiondatatask
fits
procedural-programming
exceldatareader
document-repository
packet-sniffers
addressing-mode
rickshaw
wcm
grails-plugin-rabbitmq
jjaql
ray
draw2d-js
websphere-esb
multiautocompletetextview
qscrollarea
light
solace-mq
observium
epiceditor
joomla-template
video-codecs
alice
joomla3.1
pstack
promotion-code
fsevents
lr
http-daemon
msr
django-paypal
codebase
socketserver
qglwidget
luajava
jqueryform
aspmenu
folding
web-garden
wordprocessingml
alsb
lemmatization
cardspace

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