Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. public class EventInfo extends FragmentActivity implements
  2. ActionBar.TabListener {
  3.  
  4. JSONObject obj;
  5. GoogleMap map;
  6. double latitude, longitude = 0;
  7. String address = "";
  8. String titleEvent = "";
  9.  
  10. private TextView descriptionText;
  11. private ViewPager viewPager;
  12. private TabsPagerAdapter mAdapter;
  13. private ActionBar actionBar;
  14.  
  15. // tab titles
  16. private String[] tabs = { "Event Info", "Google Map" };
  17.  
  18. protected void onCreate(Bundle savedInstanceState) {
  19.  
  20. super.onCreate(savedInstanceState);
  21.  
  22. setContentView(R.layout.eventinfo);
  23.  
  24. // Initialization:
  25. viewPager = (ViewPager) findViewById(R.id.pager);
  26. actionBar = getActionBar();
  27. mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
  28. viewPager.setAdapter(mAdapter);
  29. actionBar.setHomeButtonEnabled(false);
  30. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  31.  
  32. // Adding Tabs
  33. for (String tab_name : tabs) {
  34. actionBar.addTab(actionBar.newTab().setText(tab_name)
  35. .setTabListener(this));
  36. }
  37.  
  38. try {
  39. obj = new JSONObject(getIntent().getStringExtra("json"));
  40. Toast.makeText(getApplicationContext(),
  41. "event = " + obj.getString("summary"), Toast.LENGTH_LONG)
  42. .show();
  43. address = obj.getString("location");
  44. titleEvent = obj.getString("summary");
  45.  
  46. } catch (JSONException e) {
  47. e.printStackTrace();
  48. }
  49.  
  50. //I think the problem is somewhere in this code block!
  51. LayoutInflater inflater = getLayoutInflater();
  52. View descripText = inflater.inflate(R.layout.fragment_infofrag, null);
  53. descriptionText = (TextView) descripText.findViewById(R.id.descriptionText);
  54. descriptionText.setText("updated text"); //the textView gets updated here!
  55. Toast.makeText(getApplicationContext(), "display: "+ descriptionText.getText(), Toast.LENGTH_LONG).show(); //Toast box correctly displays, but the textView on the actual tab does not
  56. }
  57.  
  58. package com.uva.tabswipe.adapter;
  59.  
  60. import org.json.JSONException;
  61. import org.json.JSONObject;
  62.  
  63. import com.uva.tabswipe.adapter.InfoFragment;
  64. import com.uva.tabswipe.adapter.GMapFragment;
  65. import android.support.v4.app.Fragment;
  66. import android.support.v4.app.FragmentManager;
  67. import android.support.v4.app.FragmentPagerAdapter;
  68.  
  69. public class TabsPagerAdapter extends FragmentPagerAdapter {
  70.  
  71. public TabsPagerAdapter(FragmentManager fm) {
  72. super(fm);
  73.  
  74. }
  75.  
  76. @Override
  77. public Fragment getItem(int index) {
  78.  
  79. switch (index) {
  80. case 0:
  81. // Tab with event info
  82. return new InfoFragment();
  83. case 1:
  84. // Tab with Google Map Fragment (this one is working fine)
  85. return new GMapFragment();
  86. }
  87.  
  88. return null;
  89. }
  90.  
  91. @Override
  92. public int getCount() {
  93. // get item count - equal to number of tabs
  94. return 2;
  95. }
  96.  
  97. }
  98.  
  99. package com.uva.tabswipe.adapter;...
  100.  
  101. public class InfoFragment extends Fragment {
  102.  
  103. TextView descriptionText;
  104. @Override
  105. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  106. Bundle savedInstanceState) {
  107.  
  108. View rootView = inflater.inflate(R.layout.fragment_infofrag, container, false);
  109.  
  110. return rootView;
  111. }
  112. }
  113.  
  114. <?xml version="1.0" encoding="utf-8"?>
  115. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  116. android:layout_width="match_parent"
  117. android:layout_height="match_parent"
  118. android:background="#E0EEEE"
  119. android:gravity="center" >
  120.  
  121. <TextView
  122. android:id="@+id/descriptionText"
  123. android:layout_width="wrap_content"
  124. android:layout_height="wrap_content"
  125. android:gravity="center"
  126. android:textAppearance="?android:attr/textAppearanceMedium"
  127. android:textColor="#F88017"
  128. android:textSize="14sp"
  129. android:text="" />
  130.  
  131. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement