【发布时间】:2014-06-06 13:23:22
【问题描述】:
我有主要片段,我想将ArrayList 传递给Activity 类,我将在ListView 中显示结果。
片段类:
public class StudentActivity extends Fragment implements OnClickListener {
}
我有数据
ArrayList<> allStudents = new ArrayList();
allStudents.add(new Student("H", 99, 93) );
allStudents.add(new Student("C", 98, 92) );
allStudents.add(new Student("B", 98, 91) );
allStudents.add(new Student("A", 80, 94) );
allStudents.add(new Student("F", 70, 84) );
现在我想将“allStudents”对象发送到新的活动类 StudentResult();
我在片段类中使用:
Intent intent = new Intent(getActivity(), StudentResult.class);
intent.putExtra("ExtraData", allStudents);
startActivity(intent);
并在目标类中显示ListView()中的对象;
public class ResultActivity extends Activity {
public void myData(ArrayList<allStudents> myArray) {
marjslistview = (ListView) findViewById(R.id.listView1);
arrayAdapter = new ArrayAdapter<allStudents>(this, R.layout.student_list, myArray);
...
ScoreLV.setAdapter(arrayAdapter);
...
}
}
提前致谢!
【问题讨论】:
-
ArrayList菱形运算符在Android中不可用
-
"public class StudentActivity extends Fragment" 这不可能。
-
阅读文章developer.android.com/training/basics/fragments/…,你就会明白如何组织活动片段交流。
-
你在哪里接触到这个?如果您回复将不胜感激:)
标签: java android android-fragments