Hide and show of fragment

Source: Internet
Author: User

Package Com.bwie.helpdemo;

Import Com.bwie.fragment.BillFrag;
Import Com.bwie.fragment.IndexFrag;
Import Com.bwie.fragment.TaskFrag;

Import Android.os.Bundle;
Import android.app.Activity;
Import android.content.SharedPreferences;
Import android.support.v4.app.FragmentActivity;
Import Android.support.v4.app.FragmentManager;
Import android.support.v4.app.FragmentTransaction;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.TextView;

public class Indexactivity extends Fragmentactivity implements Onclicklistener {

Private Button Index_bill;
Private TextView Index_home;
Private TextView Index_task;

Private Indexfrag Indexfrag;
Private Billfrag Billfrag;
Private Taskfrag Taskfrag;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_index);

Find controls
Findview ();

Add fragment to a layout, open things
Fragmentmanager fm = Getsupportfragmentmanager ();
Fragmenttransaction tran = Fm.begintransaction ();

Indexfrag = new Indexfrag ();
Billfrag = new Billfrag ();
Taskfrag = new Taskfrag ();
R.id.relative for layout
Tran.add (r.id.relative, Indexfrag, "Index"). Show (Indexfrag)
. Add (R.id.relative, Billfrag, "Bill"). Hide (Billfrag)
. Add (R.id.relative, Taskfrag, "task"). Hide (Taskfrag);

Tran.commit ();

Set click-to-Listen for a button
Index_bill.setonclicklistener (this);
Index_home.setonclicklistener (this);
Index_task.setonclicklistener (this);
}

private void Findview () {
Index_bill = (Button) Findviewbyid (R.id.index_bill);
Index_home = (TextView) Findviewbyid (r.id.index_home);
Index_task = (TextView) Findviewbyid (r.id.index_task);

}

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Switch (V.getid ()) {
Case R.id.index_bill:
Get things
Fragmentmanager fm_1 = Getsupportfragmentmanager ();
Fragmenttransaction tran_0 = Fm_1.begintransaction ();
Tran_0.show (Billfrag). Hide (Indexfrag). Hide (Taskfrag). commit ();

Break

Case R.id.index_home:
Fragmentmanager fm_2 = Getsupportfragmentmanager ();
Fragmenttransaction tran_1 = Fm_2.begintransaction ();
Tran_1.show (Indexfrag). Hide (Billfrag). Hide (Taskfrag). commit ();

Break
Case R.id.index_task:
Fragmentmanager fm_3 = Getsupportfragmentmanager ();
Fragmenttransaction tran_2 = Fm_3.begintransaction ();
Tran_2.show (Taskfrag). Hide (Billfrag). Hide (Indexfrag). commit ();
Break
}

}
}

Hide and show of fragment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.