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

What might cause an extremely slow database writes on an Android device?
handle results from sqlite and pass them to custom list adapter
Android: Listview wont start new class fixed
Android: ImageView Rotation Scale
Phonegap Android app - not reading cookie on WIFI?
EditText fails to display inputted text the second time on Android 2.2
Unable to instantiate activity
Is ContactsContract.Contacts by default empty?
Android - Publish app use ant script
Can we added changing image/text on android app
How to add an advert pic of your app on android market
Create Navigation with offline Google Maps
What does “*” in “#*android:color/bright_foreground_dark” means for?
Confusion between ListView id position and row ID
i want to trace a variable to see it changing
Why android.app.Activity.onTrimMemory couldn't be overridden?

Categories

HOME
service-worker
django
beautifulsoup
microsoftgraph
awk
codenvy
ggplot2
amp-html
formal-languages
flex
shiro
opendj
newrelic
rom
scripting
3d-reconstruction
zip
nstableheaderview
nfs
lanczos
modal-dialog
github-enterprise
emoji
xcodebuild
dynatrace
gource
parameter-passing
gruntfile
job-scheduling
git-extensions
google-container-registry
shortest-path
production
delphi-xe5
enterprise-miner
asciidoctor-pdf
hta
easeljs
event-store
slidetoggle
realm-mobile-platform
nsurl
powershell-ise
deltaspike
gnat-gps
carriage-return
slacktextviewcontroller
apiary.io
magento-1.9.2.4
openalpr
bc
ods
c9.io
unordered-map
azure-arm
glm-math
plr
bindingnavigator
flask-restful
mschart
netbeans6.8
geotiff
reindex
amq
sundials
swingworker
structuremap4
branch-prediction
vcloud-director-rest-api
preprocessor
resourcemanager
mta
mediametadataretriever
project-organization
nullable
ascii-art
java-money
iokit
fiware-monitoring
flock
django-urls
coda
cgi-bin
typemock
baasbox
fits
xmltype
gamekit
code-documentation
exceldatareader
ejb-2.x
android-vibration
deform
draw2d-js
fpdi
maven-scm
square-bracket
mysql-error-1044
jammer
printdialog
kaleidoscope
apache-abdera
android-loadermanager
iboutlet
subgraph
kqueue
fitbounds
cross-database
box2d-iphone
luabind
clrstoredprocedure
undefined-index
drupal-fivestar
openfaces
request-headers
pagemethods
int64

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