Rampal Chaudhary
Rampal Chaudhary

Reputation: 707

Android: How is the appropriate element picked from Cursor in CursorAdapter's newView() method

I wonder how the appropriate element is picked from a Cursor when,

newView(Context context, Cursor cursor, ViewGroup parent) method of the corresponding CursorAdapter object is called as it has no parameter specifying position unlike ArrayAdapter's:

getView(int position, View convertView, ViewGroup parent) meathod:

Is the data picked from the current row pointed to by the data pointer, or in other words, is the prommer's responsibility that the correct row is being pointed to in the Cursor when newView() method is called?

Upvotes: 0

Views: 112

Answers (3)

user
user

Reputation: 87064

A cursor based adapter has the getView method implemented and this implementation calls the methods newView() and bindView() to build a view and setup the data after setting the cursor to the right position(using the position parameter of the getView method).

So the Cursor parameter will be pointing to the correct row in the methods newView and bindView because it will be already set to that position by the getView method.

Upvotes: 1

jeet
jeet

Reputation: 29199

You dont need current position of view in list in cursor adapter. Cause CursorAdapter move position automatically. But if you stil want to fetch row number, you can do by following method:

cursor.getPosition();

Upvotes: 0

Krishnakant Dalal
Krishnakant Dalal

Reputation: 3578

Form your Cursor according to your requirement. That means when you execute a query put some condition in it and it will returns the cursor according to that.

Upvotes: 0

Related Questions