How do I set position of a cursor in the Onchanged of a Customview in a ListView?

3

I'm using a customview call android-spinnerwheel . I inserted it into a listview linked to a CursorAdapter . If I use the OnitemClickListener of the ListView, the cursor goes to the corresponding position in the list and it looks beautiful ... but if I use onChanged of this view to update a hashmap in> with the value of this customview corresponding to the registry key in the cursor, as the cursor does not change its pointer ... and returns me the wrong key.

No CursorAdapter looks like this:

public class AdapterlistaPessoapub extends CursorAdapter {... 

public void BindView (View view, Context context, Cursor cursor) {... 

SpinQtde.addChangingListener (new OnWheelChangedListener () 
{
@ Override 
public void onChanged (AbstractWheel wheel, int oldValue, int newValue) {

PessoapubActivity.items.put(getCursor().getInt(getCursor().getColumnIndex(constants.FPESSOAPUB_CODPUBLICACAO)), newValue); 

Log.i (GetCursor () getString (GetCursor () getColumnIndex (constants.FvPESSOAPUB_NOMEPUBLICACAO)) + "", "New value:.." + NewValue); 

} 
}); 

Logcat returns the wrong record.

How to force the cursor to go to the correct position when executing this Onchanged , preferably without "tags"?

    
asked by anonymous 08.02.2014 / 01:01

1 answer

0

This way of accessing the cursor is unpredictable ... basically you access the position whatever the cursor is at that moment. For example, when " onChange " happens, your cursor may be pointing to the position relative to the last element in the list, but you expect it to match that of the View position you added or listener.

To ensure this, you use the moveToPosition method to go to the position of that view ... I recommend that you return to the previous position after use. To find out what position, you can set the position as " tag " of the Wheel view you gave inflate, so when the onChange method is called you can access through wheel.getTag ()

    
24.04.2014 / 19:33