Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When to use onItemClick?  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


onItemClick(AdapterView<?> parent, View view, int position, long id)

i was reading a book on android and came across this but they do not explain why they use this.what does this mean?i do not uds the explanation on the internet either.can someone use single english to explain each part and when should i use it..thankyou
 
Master Rancher
Posts: 1252
36
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what the Android API states:
https://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html

Android API wrote:AdapterView.OnItemClickListener
public static interface AdapterView.OnItemClickListener

android.widget.AdapterView.OnItemClickListener
Known Indirect Subclasses
CharacterPickerDialog,PreferenceScreen

Interface definition for a callback to be invoked when an item in this AdapterView has been clicked.

Summary
Public methods
abstract void onItemClick(AdapterView<?> parent, View view, int position, long id)
Callback method to be invoked when an item in this AdapterView has been clicked.
Public methods
onItemClick

void onItemClick (AdapterView<?> parent, View view, int position, long id)
Callback method to be invoked when an item in this AdapterView has been clicked.

Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

Parameters
parent AdapterView: The AdapterView where the click happened.
view View: The view within the AdapterView that was clicked (this will be a view provided by the adapter)
position int: The position of the view in the adapter.
id long: The row id of the item that was clicked.


I know all too well that digesting information from the API documentation can be difficult.
Hopefully my explanation listed below helps out.

Lets suppose that you have a listing of images on the screen.
The adapter is hosted in the parent view, a linear view for instance.
The adapter is connected to a view, possibly a listview, recyclerview, gridview etc.
When you click on an item you may want to know the position of the item you clicked on. Was it the first items, the last item or some item in-between?
Usually you item will have a specific id. This value could be a primary key from a database table, or some other unique

You stated that you were reading a book. What book are you reading?
 
Yl Ong
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.im reading head first android..
 
Pete Letkeman
Master Rancher
Posts: 1252
36
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I heard that book was good and any day now I should be getting a copy of it.

I do hope that you are reading the second edition of the book which was published in 2017.

A quick follow up question:
Are you new to Android development/programming or are you new to Java development/programming in general?
I have found that it has helped me to know some of the basics of Java development now that I'm exploring Android development.
 
Evil is afoot. But this tiny ad is just an ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!