私の配列リストはどういうわけか入力されます。
このコードを見てください:
final ListView list = getListView();
boolean threadNeeded = true;
//settings
list.setItemsCanFocus(false);
Bundle extras = getIntent().getExtras();
allFriends = getIntent().getParcelableExtra("shibby.whisper.allFriends");
selectedFriends = getIntent().getParcelableExtra("shibby.whisper.selectedFriends");
System.out.println("JUST ENTERED ACTIVITY : "+selectedFriends.getPositions());
if(extras !=null) {
maxPlayers = extras.getInt("max_players");
}
if(allFriends != null){
if(!allFriends.getIds().isEmpty()){
threadNeeded = false;
}
}
if(selectedFriends == null){
System.out.println("selectedFriends is null before callback from ListActivity");
selectedFriends = new PlayerList();
}
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FacebookFriendsAdapter a = (FacebookFriendsAdapter) list.getAdapter();
//select item
boolean isSelected = a.toggleSelected(new Integer(position));
//if reached maximum players and have selected a new user
if(((maxPlayers+1 == a.getMaxPlayersCounter() && maxPlayers != 0) && isSelected)
|| (maxPlayers == 0 && a.getMaxPlayersCounter() == maxAvailablePlayers+1)){
Log.e("addfriends","Max Players Reached");
a.toggleSelected(new Integer(position));
final Dialog dialog = new Dialog(FacebookFriendsListActivity.this, R.style.CustomDialogTheme );
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.maxplayers);
dialog.setCancelable(true);
// set the custom dialog components - text, image and button
Button dialogButton = (Button) dialog.findViewById(R.id.max_players_dismiss_btn);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
});
m_friends = new ArrayList<Player>();
this.m_adapter = new FacebookFriendsAdapter(this, R.layout.facebbok_friends_item, m_friends);
//set the selected friends on the adapter to remember earlier picks
if(selectedFriends != null){
oldPositions = selectedFriends.getPositions();
m_adapter.setSelectedIds(selectedFriends.getPositions());
m_adapter.setMaxPlayersCounter(selectedFriends.getIds().size());
System.out.println("Max player selected Is : "+maxPlayers+" And Selected Players Counter Is :" +m_adapter.getMaxPlayersCounter());
}
アクティビティが開始されると、selectedFriends.getPosition()
空が返されます。
ボタンをクリックすると、次のアクションを実行します。
if(oldPositions != null){
System.out.println("This is old positions : " + oldPositions);
}
これは(新しい位置によって)入力されていますが、その理由はわかりません。私はすべきではない何かを参照していますか?メモリ内のデータをオーバーライドしますか?
編集:これは、ListView から友達を選択した後に発生します。toggleSelected()
内側の ArrayList から項目を追加または削除します。