Hunt Hunt - 1 year ago 228
Android Question

get a position in bindView using CursorAdapter

i am create a listview which has two

and one custom view as a selection indicator , to load data i am using
and overriding
. but the issue is in preserving the selection index.

when i am tapping a list item , i am saving the position of it into view as follows

View v1=(View)view.findViewById(;

but inside a
i not getting a position where i can perform a match by fetching position from view's tag as follows

Integer position = (Integer) v1.getTag();

but i am not getting a position to compare just the way we get in
. i tried cur.getPosition() is the position of a record in cursor which wont match with the v1.getTag().

i tried overriding getView as follows , but not getting accurate position

public View getView(final int position, View convertView, ViewGroup parent){

this.position = position;
return super.getView(position, convertView, parent);


so how i can i get the position in bindView ? do i need to use getView or what ? i explored many threads but i didn't get any definite answer when it comes to bindView.


public void onItemClick(AdapterView<?> adapter, View view, int position,
long arg3) {

// i save the position on list item click so that when adapter loads the
// the list i can match the position with the current one


enter image description here

Answer Source

For This first you need to override getView() and set the position here and access it in bindview() later.

public View getView(int position, View convertview, ViewGroup arg2) {
    if (convbertview == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        convertview = inflater.inflate(R.layout.your layout,
    return super.getView(position, convbertview, arg2);

and in bindView() get your position like

public void bindView(View view, Context context, Cursor cursor) {
    int position=(Integer) view.getTag();//here is the position

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download