Android - How to get position in bindView like in getView?
Try this
public void bindView(View arg0, Context arg1, Cursor arg2){ int pos = arg2.getPosition();}
codeboys answer is correct, cursor.getPosition() will do.But if someone needs position in the onClick event of listitems subitem, for instance icon inside the listItem, the solution is to put a position as setTag on the icon and retreive it when event occurs:
@Overridepublic void bindView(View vw, Context ctx, final Cursor cursor) { /* ... * do your binding */ ImageView icon = (ImageView) vw.findViewById(R.id.your_icon); icon.setTag(cursor.getPosition()); // here you set position on a tag icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // use a tag to get the right position ((MainActivity) context).onIconClick((int)v.getTag()); } });}
@Overridepublic void bindView(View view, Context context, Cursor cursor) { // TODO Auto-generated method stub}@Overridepublic View newView(Context context, Cursor cursor, ViewGroup view) { // TODO Auto-generated method stub int mCount = cursor.getCount(); //Returns Total count(Rows) in cursor int currentPostion= cursor.getPosition(); //Returns the current position of the cursor in the row set}