Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------Activity
- public class TeacherListView extends FragmentActivity implements OnClickListener{
- private LinearLayout MenuList;
- private Button btnTgl;
- private int screenWidth;
- private boolean isExpanded;
- private JSONObject jsData;
- private String url;
- private int tes=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_teacher_list_view);
- Fragment fr = HomeFragment.newInstance();
- getSupportFragmentManager().beginTransaction().add(R.id.frag, fr).commit();
- MenuList = (LinearLayout) findViewById(R.id.linearLayout2);
- btnTgl = (Button) findViewById(R.id.button1);
- btnTgl.setOnClickListener(this);
- DisplayMetrics mtrcs = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(mtrcs);
- screenWidth=mtrcs.widthPixels;
- Button homeBtn = (Button) findViewById(R.id.btn_home);
- homeBtn.setOnClickListener(this);
- Button tpickBtn = (Button) findViewById(R.id.btn_tPick);
- tpickBtn.setOnClickListener(this);
- }
- public void onClick(View v){
- switch(v.getId()){
- case R.id.btn_home:
- if(isExpanded){
- collapseAnim();
- }
- addHomeFragment();
- break;
- case R.id.button1:
- if(isExpanded){
- collapseAnim();
- }else{
- expandAnim();
- }
- break;
- case R.id.btn_tPick:
- if(isExpanded){
- collapseAnim();
- }
- addTPicker();
- break;
- }
- }
- public void addHomeFragment(){
- Fragment fr = HomeFragment.newInstance();
- getSupportFragmentManager().beginTransaction().replace(R.id.frag, fr).commit();
- }
- public void addTPicker(){
- Fragment fr = TeacherPickerFragment.newInstance();
- getSupportFragmentManager().beginTransaction().replace(R.id.frag, fr, "tag").commit();
- // Fragment mf = getSupportFragmentManager().findFragmentByTag("tag");
- TeacherPickerFragment tp = (TeacherPickerFragment) getSupportFragmentManager().findFragmentByTag("tag");
- tp.changeText();
- }
- public void expandAnim(){
- isExpanded = true;
- MenuList.startAnimation(new ExpandAnimation(MenuList, 0, (int)(screenWidth*0.7),20));
- }
- public void collapseAnim(){
- isExpanded = false;
- MenuList.startAnimation(new CollapseAnimation(MenuList, 0, (int)(screenWidth*0.7),20));
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.teacher_list_view, menu);
- return true;
- }
- }
- ---------------------------------------------- fragment
- public class TeacherPickerFragment extends Fragment {
- TextView t;
- public static Fragment newInstance(){
- TeacherPickerFragment myFrag = new TeacherPickerFragment();
- return myFrag;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- Log.d("ssxx","test");
- // Inflate the layout for this fragment
- View view = inflater.inflate(R.layout.teacher_picker, container, false);
- t = (TextView) view.findViewById(R.id.randNum);
- return view;
- }
- public void changeText(){
- t.setText("test");
- }
- }
- --------------xml activity
- <FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".TeacherListView" >
- <LinearLayout
- android:id="@+id/linearLayout1"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <LinearLayout
- android:id="@+id/linearLayout2"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="0"
- android:orientation="vertical"
- android:background="#ffffff">
- <Button
- android:id="@+id/btn_home"
- android:layout_marginTop="1dp"
- android:layout_marginBottom="1dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:background="@drawable/btn_states"/>
- <Button
- android:id="@+id/btn_tPick"
- android:layout_marginTop="1dp"
- android:layout_marginBottom="1dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:background="@drawable/btn_states"/>
- <Button
- android:id="@+id/btn_rand"
- android:layout_marginTop="1dp"
- android:layout_marginBottom="1dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:background="@drawable/btn_states"/>
- <Button
- android:id="@+id/btn_supCall"
- android:layout_marginTop="1dp"
- android:layout_marginBottom="1dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:background="@drawable/btn_states"/>
- <Button
- android:id="@+id/btn_feedBack"
- android:layout_marginTop="1dp"
- android:layout_marginBottom="1dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:background="@drawable/btn_states"/>
- <Button
- android:id="@+id/btn_lgOut"
- android:layout_marginTop="1dp"
- android:layout_marginBottom="1dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:background="@drawable/btn_states"/>
- <LinearLayout
- android:id="@+id/empty"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="4"
- android:orientation="vertical"></LinearLayout>
- </LinearLayout>
- <LinearLayout
- android:id="@+id/linearLayout3"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical"
- android:background="#ff0000">
- <LinearLayout
- android:id="@+id/linearLayout5"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:orientation="vertical"
- android:background="#00ff00" >
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="ToggleMenu"
- android:layout_marginTop="2dp" />
- </LinearLayout>
- <LinearLayout
- android:id="@+id/frag"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="9"
- android:background="#0000ff"></LinearLayout>"
- </LinearLayout>
- </LinearLayout>
- </FrameLayout>
- ----------------------------xml fragment
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="#848484"
- android:id="@+id/tepi">
- <TextView
- android:id="@+id/randNum"
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:text="random number here"
- android:textSize="35sp"></TextView>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement