android


Android: Variable has two states


Sorry for the uninformative title, didn't realy know how to describe my problem in a short way. I tried so solve it since 3 hours and I have no idea, what to google for or what else to try.
I have a Recyclerview with views, that intercept the back press event via onKeyPreIme(). This is the View:
public class TestView extends LinearLayout {
int a = 1;
public TestView(Context context, AttributeSet att) {
super(context, att);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.layout, this, true);
findViewById(R.id.setBtn).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
a = 2;
}
});
findViewById(R.id.readBtn).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("LOG", "value of a: " + a);
}
});
this.setFocusable(true);
this.setFocusableInTouchMode(true);
this.requestFocus();
}
#Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
Log.i("LOG", "value of a: " + a);
return true;
}
}
Now in the beginning a = 1. After setBtn is clicked it's 2, which is confirmed when pressing readBtn. But when I press the back button, the value of a is printed as 1! If I press the readBtn afterwards, the value of a is printed as 2. This only happens on the first two views. For the following ones (those that were probably not created but reused), the behaviour is correct.

Related Links

Service from cordova plugin not starting anymore
Compilation Error: Error:(81, 18) error: cannot find symbol method addOnPageChangeListener(OnPageChangeListener)
Android Flowing Navigation Drawer
app:mergeDebugResources in Android studio
USB debugging not dectecting for my mobile [duplicate]
NullPointerException in converting retrofit response to string?
Android Animated Vector Drawable: change rotation degree at runtime
Forcing the app to work as LTR
Sliding over buttons
Google Map: Updating Location while moving?
RxJava operator that combines two observables and emits only when the first observable emits
Play audio between points A and B
Does an OnClickListener take into account the scaling factor of the view?
Multiple calls of Facebook GraphRequest crash app
Send data from Android Library to Main Project Activity
Add, remove and set CardView parameters programatically

Categories

HOME
android
batch-file
facebook-oauth
gdb
amp-html
apache-spark-mllib
composite-primary-key
gradient
sublimetext
seo
soa
pkcs#11
qpython
resultset
line
naivebayes
tput
libusb
screen-readers
gruntfile
internationalization
vuejs
google-data-studio
digital-signature
simpleitk
react-toolbox
pchart
surveymonkey
flooding
gp
gitlab-api
left-join
installshield-le
getpixel
sharding
python-pptx
xcode7.3
imagenet
projects-and-solutions
gdata
laravel-elixir
apriori
datacachefactory
softmax
wc
stylecop
phpdbg
automapper-5
configurationmanager
trojan
subnet
filehandle
d3-force-directed
juice-ui
rmongo
docpad
jclouds
lua-telegram-bot
php-socket
cda
hadoop-partitioning
beanstalk
microsoft-reporting
pax-exam
sony-lifelog-api
jsvc
zxspectrum
rrule
rmysql
raygun
with-statement
ignite-ui
verold
xmltodict
ie8-compatibility-mode
onload-event
cardreader
virtual-pc
alice
device-width
idn
midlet
vfs
kqueue
update-statement
tournament
cac
maven-1
qtabbar
lxr
feasibility
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