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

Send message to custom service via adb
Amazon SNS error on Android / titnaium
How to get the status of location access permission to warn user
libwebviewchromium.so bug in Android 5.0 WebVIew
My adapter doesn't work in the loop and my logcast
How to terminate adb.exe on windows? What keeps restarting it?
how do I get the corresponding JSON value in my JSON object?
Scroll view issue in navigation drawer
Android: Databinding expression with enum comparison
selector is not working by TypedArray
Android Unit Testing Robolectric:3.3.2 - No such manifest file
Backing up information to server
Get all realm Objects in Android
Unable find class com.google.firebase.provider.FirebaseInitProvider below API level 21
What does Android MediaRecorder.prepare() do?
Hex code color library for Android Studio

Categories

HOME
android
xml
linkedin
ng-idle
powerpoint
3d
rendering
yandex
database-normalization
visual-studio-emulator
square
x264
nstableheaderview
rcloud
android-securityexception
mod-security
mautic
selectize.js
docx
alpacajs
microsoft-dynamics-nav
sigma.js
perlbrew
angularjs-components
amazon-quicksight
firebase-analytics
paperjs
powershell-ise
card.io
installshield-le
searchkit
openalpr
reactivekit
magento-1.9.3
naming
glm-math
ntvs
chai-as-promised
identification
mongotemplate
payara-micro
excel-dna
javafx-css
usart
envi
dotnetnuke-7
macaulay2
dup
android-dateutils
pushbots
design-principles
dynamics-nav-2016
toran-proxy
cgi-bin
jdk1.7
sha512
nutiteq
nsurlsessiondatatask
mraid
node-serialport
diff3
umlgraph
ejb-2.x
angular-carousel
cuba
jquery-slider
terminate
artemis
jammer
breakout
rolify
node-blade
octal
mantle
windows-98
cascadingdropdown
android-sdk-2.3
web-farm
faye
jdb
jquery-address
jquery-tools
u2netdk
msr
codebase
eclipse-marketplace
perl5.12

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