Passing ArrayList from Fragment class to Activity

后端 未结 2 807
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 11:54

I have main fragment and I want to pass ArrayList to Activity class, where I will show the result in ListView.

Fragment class:

         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 12:38

    In your Activity:

    Bundle bundle = getIntent().getExtras(); 
    ArrayList allStudents = bundle.get("ExtraData");
    

    and I think you need to define your ArrayAdapter as:

    arrayAdapter = new ArrayAdapter(this, R.layout.student_list, allStudents);
    

    You have the rest of the code, just add the above. It should work.

提交回复
热议问题