Guest User

Untitled

a guest
May 1st, 2013
3,177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------Activity
  2. public class TeacherListView extends FragmentActivity implements OnClickListener{
  3. private LinearLayout MenuList;
  4. private Button btnTgl;
  5. private int screenWidth;
  6. private boolean isExpanded;
  7. private JSONObject jsData;
  8. private String url;
  9. private int tes=0;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_teacher_list_view);
  14. Fragment fr = HomeFragment.newInstance();
  15. getSupportFragmentManager().beginTransaction().add(R.id.frag, fr).commit();
  16. MenuList = (LinearLayout) findViewById(R.id.linearLayout2);
  17. btnTgl = (Button) findViewById(R.id.button1);
  18. btnTgl.setOnClickListener(this);
  19. DisplayMetrics mtrcs = new DisplayMetrics();
  20. getWindowManager().getDefaultDisplay().getMetrics(mtrcs);
  21. screenWidth=mtrcs.widthPixels;
  22. Button homeBtn = (Button) findViewById(R.id.btn_home);
  23. homeBtn.setOnClickListener(this);
  24. Button tpickBtn = (Button) findViewById(R.id.btn_tPick);
  25. tpickBtn.setOnClickListener(this);
  26.  
  27.  
  28.  
  29. }
  30. public void onClick(View v){
  31. switch(v.getId()){
  32. case R.id.btn_home:
  33. if(isExpanded){
  34. collapseAnim();
  35. }
  36. addHomeFragment();
  37. break;
  38. case R.id.button1:
  39. if(isExpanded){
  40. collapseAnim();
  41. }else{
  42. expandAnim();
  43. }
  44. break;
  45. case R.id.btn_tPick:
  46. if(isExpanded){
  47. collapseAnim();
  48. }
  49. addTPicker();
  50. break;
  51. }
  52. }
  53. public void addHomeFragment(){
  54. Fragment fr = HomeFragment.newInstance();
  55. getSupportFragmentManager().beginTransaction().replace(R.id.frag, fr).commit();
  56.  
  57. }
  58. public void addTPicker(){
  59.  
  60. Fragment fr = TeacherPickerFragment.newInstance();
  61. getSupportFragmentManager().beginTransaction().replace(R.id.frag, fr, "tag").commit();
  62. // Fragment mf = getSupportFragmentManager().findFragmentByTag("tag");
  63. TeacherPickerFragment tp = (TeacherPickerFragment) getSupportFragmentManager().findFragmentByTag("tag");
  64. tp.changeText();
  65. }
  66.  
  67. public void expandAnim(){
  68. isExpanded = true;
  69. MenuList.startAnimation(new ExpandAnimation(MenuList, 0, (int)(screenWidth*0.7),20));
  70. }
  71. public void collapseAnim(){
  72. isExpanded = false;
  73. MenuList.startAnimation(new CollapseAnimation(MenuList, 0, (int)(screenWidth*0.7),20));
  74. }
  75. @Override
  76. public boolean onCreateOptionsMenu(Menu menu) {
  77. // Inflate the menu; this adds items to the action bar if it is present.
  78. getMenuInflater().inflate(R.menu.teacher_list_view, menu);
  79. return true;
  80. }
  81.  
  82.  
  83. }
  84. ---------------------------------------------- fragment
  85. public class TeacherPickerFragment extends Fragment {
  86. TextView t;
  87. public static Fragment newInstance(){
  88. TeacherPickerFragment myFrag = new TeacherPickerFragment();
  89. return myFrag;
  90. }
  91.  
  92. @Override
  93. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  94. Bundle savedInstanceState) {
  95. Log.d("ssxx","test");
  96. // Inflate the layout for this fragment
  97. View view = inflater.inflate(R.layout.teacher_picker, container, false);
  98. t = (TextView) view.findViewById(R.id.randNum);
  99. return view;
  100. }
  101. public void changeText(){
  102. t.setText("test");
  103. }
  104. }
  105. --------------xml activity
  106. <FrameLayout
  107. xmlns:android="http://schemas.android.com/apk/res/android"
  108. xmlns:tools="http://schemas.android.com/tools"
  109. android:layout_width="match_parent"
  110. android:layout_height="match_parent"
  111. tools:context=".TeacherListView" >
  112. <LinearLayout
  113. android:id="@+id/linearLayout1"
  114. android:layout_width="match_parent"
  115. android:layout_height="match_parent">
  116. <LinearLayout
  117. android:id="@+id/linearLayout2"
  118. android:layout_width="0dp"
  119. android:layout_height="match_parent"
  120. android:layout_weight="0"
  121. android:orientation="vertical"
  122. android:background="#ffffff">
  123. <Button
  124. android:id="@+id/btn_home"
  125. android:layout_marginTop="1dp"
  126. android:layout_marginBottom="1dp"
  127. android:layout_width="match_parent"
  128. android:layout_height="0dp"
  129. android:layout_weight="1"
  130. android:background="@drawable/btn_states"/>
  131. <Button
  132. android:id="@+id/btn_tPick"
  133. android:layout_marginTop="1dp"
  134. android:layout_marginBottom="1dp"
  135. android:layout_width="match_parent"
  136. android:layout_height="0dp"
  137. android:layout_weight="1"
  138. android:background="@drawable/btn_states"/>
  139. <Button
  140. android:id="@+id/btn_rand"
  141. android:layout_marginTop="1dp"
  142. android:layout_marginBottom="1dp"
  143. android:layout_width="match_parent"
  144. android:layout_height="0dp"
  145. android:layout_weight="1"
  146. android:background="@drawable/btn_states"/>
  147. <Button
  148. android:id="@+id/btn_supCall"
  149. android:layout_marginTop="1dp"
  150. android:layout_marginBottom="1dp"
  151. android:layout_width="match_parent"
  152. android:layout_height="0dp"
  153. android:layout_weight="1"
  154. android:background="@drawable/btn_states"/>
  155. <Button
  156. android:id="@+id/btn_feedBack"
  157. android:layout_marginTop="1dp"
  158. android:layout_marginBottom="1dp"
  159. android:layout_width="match_parent"
  160. android:layout_height="0dp"
  161. android:layout_weight="1"
  162. android:background="@drawable/btn_states"/>
  163. <Button
  164. android:id="@+id/btn_lgOut"
  165. android:layout_marginTop="1dp"
  166. android:layout_marginBottom="1dp"
  167. android:layout_width="match_parent"
  168. android:layout_height="0dp"
  169. android:layout_weight="1"
  170. android:background="@drawable/btn_states"/>
  171. <LinearLayout
  172. android:id="@+id/empty"
  173. android:layout_width="match_parent"
  174. android:layout_height="0dp"
  175. android:layout_weight="4"
  176. android:orientation="vertical"></LinearLayout>
  177. </LinearLayout>
  178. <LinearLayout
  179. android:id="@+id/linearLayout3"
  180. android:layout_width="0dp"
  181. android:layout_height="match_parent"
  182. android:layout_weight="1"
  183. android:orientation="vertical"
  184. android:background="#ff0000">
  185. <LinearLayout
  186. android:id="@+id/linearLayout5"
  187. android:layout_width="match_parent"
  188. android:layout_height="0dp"
  189. android:layout_weight="1"
  190. android:orientation="vertical"
  191. android:background="#00ff00" >
  192. <Button
  193. android:id="@+id/button1"
  194. android:layout_width="wrap_content"
  195. android:layout_height="wrap_content"
  196. android:text="ToggleMenu"
  197. android:layout_marginTop="2dp" />
  198. </LinearLayout>
  199. <LinearLayout
  200. android:id="@+id/frag"
  201. android:layout_width="match_parent"
  202. android:layout_height="0dp"
  203. android:layout_weight="9"
  204. android:background="#0000ff"></LinearLayout>"
  205. </LinearLayout>
  206. </LinearLayout>
  207. </FrameLayout>
  208. ----------------------------xml fragment
  209. <?xml version="1.0" encoding="utf-8"?>
  210. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  211. android:layout_width="match_parent"
  212. android:layout_height="match_parent"
  213. android:orientation="vertical"
  214. android:background="#848484"
  215. android:id="@+id/tepi">
  216. <TextView
  217. android:id="@+id/randNum"
  218. android:layout_width="match_parent"
  219. android:layout_height="150dp"
  220. android:text="random number here"
  221. android:textSize="35sp"></TextView>
  222.  
  223. </LinearLayout>
RAW Paste Data