android


Get access to particular item's layout in list view


In my android app my Main Activity extends List Activity. I store there elements called Items, their layout is defined by itemLayout xml file and I use custom adapter (called ItemAdapter) to transfer data to List View in Main Activity. In itemLayout there's an ImageView and my aim is to change its image when user clicks on the particular item in list view. In my opinion the easiest way to achieve that is to get access to particular item's (the one that was clicked) layout, there find the ImageView and call method setImageBitmap. How can I "find" this layout of clicked item? I tried many things in method:
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
}
but nothing worked. Do I have to add anything to my ItemAdapter? Or is it possible to do in onListItemClick(…) but I can't find out how?
You're thinking about it in slightly the wrong way. Adapter's are a way to map data to views. So if you want to change how a particular view looks for a given position, you need to change it's correlating data so that the rendered View then changes. Attempting to modify a view directly kinda goes against how adapters are meant to be used.
So in your case, when a user clicks on an item. Find that item in your adapter via the position number. Then update the item and ensure notifydataset is called. Meanwhile, your adapter's getView() will then handle displaying the appropriate image.
As I understood you need to modify clicked item layout, right? Use argument from onListItemClicked:
v.findViewById(<your_img_view_id>)
For better performance use view holder.
onListItemClick is fired when you press on an element of the ListView. If you want to retrieve the element in the dataset, you can simply invoke
l.getItemAtPosition(position)
the returned value has to be casted to the specific object
Yes It is possible in your custom adapter class in the getView() mtheod u can change imageview bitmap by clicking on it
see this code
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;
rowView = inflater.inflate(R.layout.playlist_item, null);
final ImageView im = (ImageView) rowView.findViewById(R.id.favorite);
im.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Do your stuff here
}
});
return rowView;
}

Related Links

Android: Finding if service is running or not from widget after app is killed
Adding Spring for Android into Android Studio project
Systrace no longer works on Nexus 6 in Marshmallow because of SELinux? Has anyone got it working again?
android - what devices support which sensors [closed]
Serialize android USB incomming data
Cannot change identity of an already logged in user in realm
Querying with two criteria in Firebase on Android
Firebase 2.0 - how to deal with multiple flavors (environments) of an android app?
zooming, dragging an image causing image loading delay
Android Gallery Thumbnail Images
How to turn off physical keyboard through adb command?
How to limit parallel requests with Retrofit 2.0?
Chromwebdriver problen when installing appium
readParcelable returns null
Template Proposals in Android Studio
ActionBarDrawerToggle in activity breaks options menu in fragments

Categories

HOME
kentico
polymer
rdbms
ns-3
youtube-data-api-v3
components
vscode-extensions
permissions
cq5
mips
3d-reconstruction
pearson-correlation
trac
accessibility
activecollab
azure-powershell
azure-iot-hub
scsi
dimensional-modeling
nodemcu
connector
sencha-touch
replication
short-url
android-sharedpreferences
appirater
8051
android-things
spotipy
user-defined-functions
carrierwave
google-cast
github3.py
browser-extension
searchkit
zoomify
odroid
demo
levenshtein-distance
naming
opencmis
term
wcftestclient
carrot2
azure-cli
ngmaterial
oozie-coordinator
vibrate
django-1.10
shinobi
filenet
testrail
stripe-connect
meteor-packages
xcode-server
tinkerpop3
flex4.6
model-associations
android-wake-lock
hadoop-partitioning
upx
lz77
exim4
concept-insights
asyncdisplaykit
relativelayout
assertion
microsoft-reporting
flock
intel-c++
sha512
baasbox
node-serialport
broadband
administration
sql-scripts
easyrtc
appserver
device-tree
psr-4
ray
clickbank
mt4j
diem
web-notifications
boost-msm
paginator
oracle-enterprise-linux
kqueue
hibernateexception
htdocs
entitydatasource
svk
nhprof
presentation-layer
resharper-6.0
silent
dot-emacs
web-garden
localizable.strings

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