2012-04-22 21 views
0

次のコードを使用してListViewをリロードしています。 ListViewの位置が保持されるように、どうすればよいですか?ListViewの位置を維持する

protected void refreshListView() { 
    datasource = new DataSource(this); 
    try { 
     datasource.ScanVirtualSystems(); 
    } catch (Exception e) { 
     Log.w("Exception", "exception in ScanVirtualSystems() method"); 
    } 
    MatrixCursor cursor; 
    cursor = datasource.getnameList(); 
    startManagingCursor(cursor); 
    String[] from = { "name", "desc", "status", "path", "folder", 
      BaseColumns._ID }; 
    int[] to = { R.id.name, R.id.desc, R.id.status, R.id.path }; 
    final CustomSCAdapter adapter = new CustomSCAdapter(
      Mactivity.this, R.layout.row, cursor, from, to); 
    adapter.notifyDataSetChanged(); 
    setListAdapter(adapter); 
} 

答えて

1
protected void refreshListView() { 

    ListView lv = getListView(); 
    int position = lv.getFirstVisiblePosition(); 

    datasource = new DataSource(this); 
    try { 
     datasource.ScanVirtualSystems(); 
    } catch (Exception e) { 
     Log.w("Exception", "exception in ScanVirtualSystems() method"); 
    } 
    MatrixCursor cursor; 
    cursor = datasource.getnameList(); 
    startManagingCursor(cursor); 
    String[] from = { "name", "desc", "status", "path", "folder", 
      BaseColumns._ID }; 
    int[] to = { R.id.name, R.id.desc, R.id.status, R.id.path }; 
    final CustomSCAdapter adapter = new CustomSCAdapter(
      Mactivity.this, R.layout.row, cursor, from, to); 
    adapter.notifyDataSetChanged(); 
    setListAdapter(adapter); 

    lv.smoothScrollToPosition(position); 
} 
+0

あなたの最初の答えは、この1つはちょうど最初の子にスクロールし、働いていたものでした。 –

関連する問題