2013-11-28 174 views
0

我試圖在ListFragment中設置初始滾動位置,但沒有成功。我試圖做到以下幾點:在ListFragments中設置滾動位置

public abstract class AbstractDiaListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> { 

(...) 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 

     ListView mList = this.getListView(); 

     mList.setSelection(position) 

    } 

我使用smoothScrollToPosition已經嘗試過,並使用onViewCreated()試圖代替onActivityCreated。我錯過了什麼嗎?

謝謝!

回答

0

嘗試使用:

  mList.post(new Runnable() { 
        @Override 
        public void run() { 
         mList.setSelection(position); 
        } 
      });