Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. AgendaFragment agenda = new AgendaFragment();
  2. String label = getResources().getString(R.string.title_activity_list);
  3. FragmentTransaction ft = getFragmentManager().beginTransaction();
  4. Bundle bundle = new Bundle();
  5. bundle.putString("date", date);
  6. agenda.setArguments(bundle);
  7. ft.replace(R.id.pager, agenda, label);
  8. ft.commit();
  9.  
  10. public class AgendaFragment extends Fragment {
  11.  
  12. private Context mContext;
  13. ArrayList<String> mDate;
  14. Vector<List<String>> mMappedInfo;
  15.  
  16. @Override
  17. public void onActivityCreated(Bundle savedInstanceState){
  18. super.onActivityCreated(savedInstanceState);
  19.  
  20. mContext = (Context) getActivity();
  21. mDate = new ArrayList<String>();
  22. mMappedInfo = new Vector<List<String>>();
  23.  
  24. //...
  25. //Get necessary information from server.
  26. serverCommunication();
  27. }
  28.  
  29. private void serverCommunication() {
  30.  
  31. new AsyncTask<Void, Void, Boolean>() {
  32. //get information
  33.  
  34. @Override
  35. protected void onPostExecute(Boolean result) {
  36. super.onPostExecute(result);
  37.  
  38. if (result) {
  39. //parse data
  40. apptXmlParsing(mCompleteXml);
  41. }
  42.  
  43. }
  44.  
  45. }.execute();
  46.  
  47. }
  48.  
  49. public void apptXmlParsing(final XmlDom completeXml) {
  50. //Parse received data
  51. populateListView();
  52. }
  53.  
  54. private void populateListView(){
  55.  
  56. final ExpandableListView eLV = (ExpandableListView) getActivity().findViewById(R.id.expListView);
  57.  
  58. //process data into acceptable format
  59.  
  60. ExpandableListAdapter listAdapter = new ExpandableListAdapter(mContext, mDate, mMappedInfo, mCurrDate);
  61. eLV.setAdapter(listAdapter);
  62.  
  63. }
  64.  
  65. }
  66.  
  67. public ExpandableListAdapter(Context c, List<String> mDate, ArrayList<HashMap<String, String>> mMappedInfo, List<String> mCurrDate) {
  68. this.context = c;
  69. this.mDateVariable = mDate;
  70. this.mMappedInfoVariable = mMappedInfo;
  71. this.mCurrDateVariable = mCurrDate;
  72. }
  73.  
  74. // use the Objects with the new datas as parameters
  75. public void loadNewData(List<String> NewmDate, ArrayList<HashMap<String, String>> NewmMappedInfo, List<String> NewmCurrDate) {
  76. // Then, repopulate your variables
  77. this.mDateVariable = NewmDate;
  78. this.mMappedInfoVariable = NewmMappedInfo;
  79. this.mCurrDateVariable = NewmCurrDate;
  80. // Call the method to redraw your list item
  81. notifyDataSetChanged();
  82. }
  83.  
  84. listAdapter.loadNewData(mDate,mMappedInfo,mCurrDate);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement