【发布时间】:2014-07-10 04:01:38
【问题描述】:
我确定我错过了一些愚蠢的事情,这不可能这么难......
我正在将一个整数数组列表从一个类传递到另一个类。日志显示传递类中的数据是正确的,但在接收类中总是显示为空。 所有其他意图数据均已正确传递。
ArrayList unsavedEditedSets 是私有类变量。
请帮忙。
通过类段:
holder.returnButton.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
unsavedEditedSets.add(setPositionChoice);
Intent i = new Intent(SetEditor.this, DisplayFullWorkout.class);
i.putIntegerArrayListExtra("use", unsavedEditedSets);
Log.d("INIT - OK",""+unsavedEditedSets); // This shows data is in the arraylist
i.putExtra("subsets", subsetsList);
i.putExtras(extras);
startActivity(i);
}
});
捕捉类:
private ArrayList<Integer> unsavedEditedSets;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_full_workout);
Intent incomingI = getIntent();
subsetsList = (ArrayList<HashMap<String, String>>)incomingI.getSerializableExtra("subsets");
unsavedEditedSets = (ArrayList<Integer>) incomingI.getIntegerArrayListExtra("use");
extras = incomingI.getExtras();
Log.d("Incoming - BAD",""+unsavedEditedSets); // This shows null arraylist
}
在发送前尝试使用新的数组列表,但仍然为空:
ArrayList<Integer> test = new ArrayList<Integer>();
test.add(12);
test.add(19);
i.putExtra("use", test); Log.d("INIT - OK",""+test);
【问题讨论】:
-
日志仅显示:Init - OK [1] 和 Incoming - Bad null
-
尝试传递相同的“子集”意味着 SerializableExtra。
-
谢谢@Haresh,我原来是这样的,它返回null。刚刚又试了一次,以防万一……还是空。
-
能否提供捕获类中
unsavedEditedSets的定义? -
如果删除
putExtras和putExtra("subsets"...)会怎样?extras是否偶然包含"use"?
标签: android android-intent arraylist