As the title says, I want to know the exact position of the element when I click on the view inside the element.
Suppose I have the following code in the getView () method of an ArrayAdapter:
...
holder = new ViewHolder ();
holder.iconAction = (ImageView)convertView.findViewById (R.id.download_item_iconAction);
holder.iconAction.setOnClickListener (new View.OnClickListener(){
@Override
public void onClick (View v){
}
});
...
Inside onClick () I know that click, v, but I do not know the position of the element.
Let me do the trick. I am going to save a position in ViewHolder when getView () creates a view:
public View getView (int position, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null){
holder = new ViewHolder ();
holder.iconAction = (ImageView)convertView.findViewById (id);
holder.iconAction.setOnClickListener (new View.OnClickListener(){
@Override
public void onClick (View v){
int pos = (Integer)v.getTag ();
}
});
holder.iconWait.setTag (position);
...
}else{
holder = (ViewHolder)convertView.getTag ();
}
...
}
... . , , . , 10 5 ( : 1 , ). , , , (0) . , , , , - (0).
: 0, 1, 2, 3, 4 5. (6) 0: .
- ListView OnItemClickListener:
listView = getListView ();
listView.setOnItemClickListener (new AdapterView.OnItemClickListener(){
@Override
public void onItemClick (AdapterView<?> parentView, View childView, int position, long id){
...
}
});
, , , , , .
.