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

How to match/pair random users in mobile app games?
How to gradually slide out view when list or scroll view is scrolled like bottom options in current facebook app
How to hide/show custom title layout when scrolling webview
PHP MySQL to android not retrieving data if wifi connection is changed
How to use cache and server for display icon?
SIGSEV in async tasks on Xamarin Android
finish score activity to return back to surfaceview
GoogleAuthUtil like device authentication for iOS to verify that requests originate from an Apple device
Android DialogFragment done button clickable
remembering app's data after app has been closed and restarted again
Get website source code from WebView
Android: How to get requestCode inside alarm receiver when Alarm rings
Could not find class com.google.android.gms.analytics.GoogleAnalytics
Can no longer open android app (until reinstall)
How to send same message one by one to a multiple device via bluetooth in android?
How works photoView in Facebook android application?

Categories

HOME
url-redirection
gridview
c++11
eslint
numbers
knitr
rendering
bitbucket-api
seo
soa
vxml
visual-studio-emulator
vert.x
spin
g++
categorical-data
enthought
siddhi
gkturnbasedmatch
pybossa
heat
bitnami
gruntfile
linear-algebra
firefox-addon
cfml
visual-glitch
spring-async
highstock
strongname
linked-data
openmdao
winpe
eviews
sql-delete
sharepoint-workflow
apiary.io
wurfl
release
bc
signals-slots
trigonometry
dbnull
install.packages
plr
signal-strength
monkey-testing
servermanager
double-click
magento-2.0.7
linter
netbeans6.8
bluez
oozie-coordinator
libjpeg
reachability
chromium-os
docpad
grails-plugin
builtins
udpclient
dbamp
directdraw
themoviedb-api
doctype
visual-sourcesafe-2005
rpart
lasso
liquid-layout
diff3
nsmenu
memset
vbe
twitter-bootstrap-rails
menubar
gae-quotas
koala
qscrollarea
multitasking
android-usb
mbunit
ice-cube
unit-of-work
windows-98
dopostback
extreme-programming
cakephp-1.2
boost-signals
appjs
usertype
google-maps-mobile
agility.js
node-redis
role
htdocs
winmain
entitydatasource
timthumb
django-paypal
timertask
delimited-text
hbm2java
request-headers
data-mapping
dsl-tools
application-planning
technical-debt
contentpresenter
commercial-application

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