0

我在将数据从 移动Cursor到 时遇到了麻烦PageFragment。我从 中读取所有数据Cursor,但PageFragment只有最后一个值。所以位置继续(0,1,2,..),但从光标开始它只到最后一个。

我怎么解决这个问题?

请帮忙!

public android.support.v4.app.Fragment getItem(int position) {      
          while (cursor.moveToNext()){
            GlobalVars.ditty = cursor.getString(cursor.getColumnIndex(DB.COLUMN_DIT));          
          }                         
return PageFragment.newInstance(position, GlobalVars.ditty);        
}

public static class GlobalVars {
       public static String ditty;    
}
4

1 回答 1

0

我从光标读取所有数据,但在 PageFragment 中只有最后一个值

因为在 while 循环中,您在每次迭代中都为新值分配了新值,GlobalVars.ditty所以要么用分隔符附加新值,GlobalVars.ditty要么使用任何数据结构来存储值,如 ArrayList、HashMap、...:

while (cursor.moveToNext()){
            GlobalVars.ditty += 
               cursor.getString(cursor.getColumnIndex(DB.COLUMN_DIT));          
          }  
于 2013-12-07T01:36:48.483 回答