我在我的項目中有一個列表視圖,它包含圖像和信息。
SO假設它包含50人的信息。 現在,如果我想刪除最後兩個項目,刪除最後一個項目後,listlview自動聚焦到列表的頂部。
所以,現在用戶已經向下滾動所有項目以到達第49項並刪除它。
那麼是否有任何方法來解決從我刪除該項目的位置的列表視圖位置。對於刪除信息Listview自動滾動到頂部
//代碼
public void deleteFeed(int rowID) {
// fetch the image File name
Cursor cursor = dbAdapter.getTimelineFeedByID(mSysPrefs.getBabyID(), rowID);
if(cursor != null && cursor.moveToFirst()) {
// fetch from DB Cursor
String imageFileName = cursor.getString(cursor.getColumnIndex(DatabaseAppHelper.KEY_IMAGENAME));
File file = new File(GlobalConstants.FILE_PATH, imageFileName + GlobalConstants.IMAGE_EXTENSION);
if(file.exists()) {
file.delete();
}
//listview.smoothScrollToPosition(0, listview.getHeight());
listview.smoothScrollToPosition(0, listview.getBottom());
}
// now delete the record from the DB
if(dbAdapter.deleteTimelineFeed(rowID) != -1) {
onResume();
} else {
Toast.makeText(this, "Please try again..", Toast.LENGTH_LONG).show();
}
}
的列表視圖創建
//代碼
@Override
protected void onResume() {
super.onResume();
turnGPSOn(); // method to turn on the GPS if its in off state.
getMyCurrentLocation();
dbAdapter.openDBConnection();
new Handler().post(new Runnable() {
@Override
public void run() {
timelineCursorAdapter = new TimelineCursorAdapter(TimelineViewActivity.this,
dbAdapter.getAllTimelineFeedsForBaby(mSysPrefs.getBabyID()), 0);
listview.setAdapter(timelineCursorAdapter);
//timelineCursorAdapter.notifyDataSetChanged();
listview.invalidateViews();
}
});
}
嘗試'listView.setSelectionAfterHeaderView();'或'list.smoothScrollToPosition(0);' – 2015-02-11 10:32:13
你可以發佈你正在使用的代碼嗎?它會更容易幫助你, – 2015-02-11 10:33:56