2016-04-06 2 views
0

現在、チェックされているインデックスリストビューの項目をクリックすると、正常に動作します。リストビュー位置をシャッフルするには?

要件: しかし、今、私はすべてが上部と下部にあるすべてのチェックボックスをオフにリストビューのインデックスを確認見せたい、誰も私を助けてくださいことはできますか?事前に

おかげでsharepreferanceを使用してリストビューの位置を確認するためのクラスを使用して

、以下に挙げる:

public class ColorSessionManager { 

public static ArrayList<Boolean> listBoolTrain = new ArrayList<Boolean>(); 

private int giftRemaining; 

private SharedPreferences prefs; 

// Editor for Shared preferences 
Editor editor; 

// Context 
Context _context; 

// Shared pref mode 
int PRIVATE_MODE = 0; 

// Sharedpref file name 
private static final String PREF_NAME = "AndroidHivePref"; 

public ColorSessionManager(Context context) { 
    this._context = context; 

    prefs = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); 

    editor = prefs.edit(); 
} 

public void setNumberOfGits(int numberOfGifts) { 
    editor.putInt("numberOfGifts", numberOfGifts); 

    editor.commit(); 
} 

public int getNumberOfGits() { 
    int nog = prefs.getInt("numberOfGifts", -5); 

    return nog; 
} 

public void initializerBooleans(int arraySiz) { 
    int arraySize = prefs.getInt("arraySize", 10); 

    for (int x = 0; x < arraySize; x++) { 
     editor.putBoolean("Bool" + x, false); 

     editor.commit(); 
    } 
} 

public void setItemVisited(int x) { 
    editor.putBoolean("Bool" + x, true); 

    editor.commit(); 
} 

public boolean isItemVisited(int x) { 
    return prefs.getBoolean("Bool" + x, false); 
} 

public int getUnVisitedItemCount() { 
    int count = 0; 

    int arraySize = prefs.getInt("arraySize", 10); 

    for (int x = 0; x < arraySize; x++)// listBoolTrain.size(); x++) 
    { 
     boolean bol = prefs.getBoolean("Bool" + x, false); 

     if (!bol) { 
      count++; 
     } 
    } 

    return count; 
} 

public void remainingGift() { 
} 

public void setFirstRun(boolean status) { 
    editor.putBoolean("firstrun", status); 

    editor.commit(); 
} 

public boolean getFirstRun() { 
    return prefs.getBoolean("firstrun", true); 
} 

public void removeAllPreferences() { 
    prefs.edit().clear().commit(); 
} 

public void removeKey(String keyName) { 
    prefs.edit().remove(keyName).commit(); 
} 

public void showAll() { 
    Map<String, ?> keys = prefs.getAll(); 

    for (Map.Entry<String, ?> entry : keys.entrySet()) { 
     Log.d("map values", entry.getKey() + ": " 
       + entry.getValue().toString()); 
    } 
} 

public void setArraySize(int boolSize) { 
    editor.putInt("arraySize", boolSize); 

    editor.commit(); 

    initializerBooleans(boolSize); 
} 

public int getArraySize() { 
    return prefs.getInt("arraySize", -1); 
} 

public boolean ItemVisited(int position) { 
    return prefs.getBoolean("Bool" + position, false); 

} 

} 

答えて

0
@Override 
    public void onListItemClick(ListView listview, View view, int position, long id) { 
     super.onListItemClick(listview, view, position, id); 
     listview.setItemChecked(position, true); 

} 

を選択してチェックし、未チェックの項目

final SparseBooleanArray checked = getListView().getCheckedItemPositions(); 
for (int i=0; i < checked.size(); i++) { 
      if (checked.valueAt(i)) { 
       ..... 
      } else { 
       ..... 
      } 
} 
関連する問題