Uygulamamda da benzer bir ihtiyacım vardı. Listenin konumunu tanımlamak için getListView().setSelection()
'u kullandım, kaydırma yapmadan iyi çalışıyor.
size 2 aktivitelere sahip düşünüyorsanız, yeni bir öğe eklemek için bir form olan bir imleç ve ActivityB dan listesini gösterir ActivityA. bitirmek günü, ActivityB madde imleç kimliği dönmelidir, ardından ActivityB
kimlikli öğenin konumunu alabilir ve bu kodu gibi pozisyon ayarlayın:
/* check intent Id to scroll to the right item after update or delete */
if (getIntent().hasExtra(ITEMID_INTENT_KEY))
{
long id = getIntent().getLongExtra(ITEMID_INTENT_KEY, 0);
int position = getPositionFromId(id);
getListView().setSelection(position > 0 ? position - 1 : 0);
getIntent().removeExtra(ITEMID_INTENT_KEY);
}
(...)
private int getPositionFromId(long id)
{
mCursor.moveToFirst();
do
{
Long cursorId = mCursor.getLong(mCursor.getColumnIndexOrThrow(yourIdColumn));
if (cursorId.longValue() == id)
{
return mCursor.getPosition();
}
}
while (mCursor.moveToNext());
return 0;
}