需要在activity之间传递数据,遇到一些困难。
代码:
private TextView createNewTextView (String text){
final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
final TextView newTextView = new TextView(this);
ArrayList<String> players = new ArrayList<String>();
Intent zacniIgro = getIntent();
newTextView.setLayoutParams(lparams);
newTextView.setText(text);
players.add(text);
zacniIgro.putStringArrayListExtra("players", players);
return newTextView;
}
public void zacniIgro (View v){
Intent zacniIgro = new Intent (getApplicationContext(), Igra.class);
startActivity(zacniIgro);
}
在新的activity中如何得到数据?我试过:
ArrayList<String> players = data.getStringArrayListExtra("players");
检索列表:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_igra);
ArrayList<String> players = data.getStringArrayListExtra("players");
}
给data加了红下划线。不知道是什么错误。