How to set position of a cursor in the Onchanged of a Customview in a Listview?

Asked

Viewed 218 times

4

I’m wearing a customview calling for android-spinnerwheel. I inserted her into a listview connected to a CursorAdapter. If I use the OnitemClickListener from Listview, the cursor goes to the corresponding position of the list and everything looks beautiful... but, if I use the onChanged of this view to update a hashmap with the value of this customview corresponding to the registry key on the cursor, as the cursor does not change its pointer... and returns me the wrong key.

In the CursorAdapter was 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); 

} 
}); 

The logcat returns me the wrong record.

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

  • onChanged of which View? Without the code becomes complicated.

  • "I’m using a customview called android-spinnerwheel."

1 answer

0


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.