문제

I' ve a troble with moving data from Cursor to PageFragment. I read all data from Cursor, but in PageFragment goes only last value. So positions go ahead(0,1,2,..), but from cursor it goes only last one.

How can I solve this problem?

HELP, please!

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;    
}
도움이 되었습니까?

해결책

I read all data from Cursor, but in PageFragment goes only last value

Because inside while loop you are assigning new value to GlobalVars.ditty in each iteration so either append new value to GlobalVars.ditty with separator or use any data structure to store values like ArrayList,HashMap,... :

while (cursor.moveToNext()){
            GlobalVars.ditty += 
               cursor.getString(cursor.getColumnIndex(DB.COLUMN_DIT));          
          }  
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top