Click on the button, the first automatic Drop-down refresh, you can manually refresh, after the refresh, the last one more than one row of data. There are four tabs.
A couple of days ago, the instructor asked to make a reservation for an undergraduate student in the room, starting from here. Do do to meet a lot of problems, have been solved. This effect feels good, tidy up.
Mainactivity
Package com.example.fragmentmytest;
Import Android.content.DialogInterface;
Import Android.graphics.Color;
Import Android.os.Bundle;
Import android.support.v4.app.FragmentActivity;
Import Android.support.v4.app.FragmentManager;
Import android.support.v4.app.FragmentTransaction;
Import Android.text.TextUtils;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.TextView;
Import Com.example.dialog.CustomDialog;
Import COM.EXAMPLE.DIALOG.CUSTOMDIALOGCHANGEPWD;
Import com.example.dialog.CustomDialogSignUp;
Import com.example.myapplication.CustomApplication;
Import Com.example.utils.ToastUtils; public class Mainactivity extends fragmentactivity {public static final String serveraddress = "http://192.168.1.101"; pu
Blic static final String ServerPort = "8080";
Onefragment onefragment;
Twofragment twofragment;
Threefragment threefragment;
Fourfragment fourfragment; Button btn1, Btn2, Btn3, Btn4;
Onclicklistener Clicklistener;
TextView stu_msg;
Private CustomApplication app;
/** * for the Fragment management * * Fragmentmanager Fragementmanager; protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main); App = (customapplication) getapplication ();
Get CustomApplication object//must inherit fragmentactivity to use Getsupportfragmentmanager (); it's best to use V4.app, it's not how anyone uses the app.
Fragementmanager = Getsupportfragmentmanager ();
Init ();
The No. 0 tab settabselection (0) is selected on the first startup and/or the default value that cannot be slid left and right} is public void init () {stu_msg = (TextView) Findviewbyid (r.id.stu_msg);
BTN1 = (Button) Findviewbyid (R.ID.BTN1);
BTN2 = (Button) Findviewbyid (R.ID.BTN2);
Btn3 = (Button) Findviewbyid (R.ID.BTN3);
Btn4 = (Button) Findviewbyid (R.ID.BTN4); Clicklistener = new Onclicklistener () {public void OnClick (View arg0) {int id = arg0.getid (), switch (ID) {Case r.id.bt
N1:settabselection (0);
Break
Case R.id.btn2:settabselection (1);
Break Case R.id.btn3:sEttabselection (2);
Break
Case R.id.btn4:settabselection (3);
Break
Default:break;
}
}
};
Btn1.setonclicklistener (Clicklistener);
Btn2.setonclicklistener (Clicklistener);
Btn3.setonclicklistener (Clicklistener);
Btn4.setonclicklistener (Clicklistener); private void settabselection (int index) {clearselection ();//Clear the last selected state/open a fragment transaction before each check fragmenttransaction t
Ransaction = Fragementmanager.begintransaction ();
Hide all the fragment first to prevent multiple fragment from appearing on the interface Hidefragements (transaction); Switch (index) {case 0:btn1.setbackgroundcolor (Color.parsecolor ("#CFEFEF")); Btn1.settextcolor (Color.parsecolor ("#
FFFFFF "));
App.setroom (Btn1.gettext (). toString ()); if (onefragment = = null) {onefragment = new onefragment (); Transaction.add (R.id.framelayout, onefragment);} else {trans
Action.show (onefragment);
Onefragment.mPullRefreshListView.setRefreshing (TRUE);
} break;
Case 1:btn2.setbackgroundcolor (Color.parsecolor ("#CFEFEF"));
Btn2.settextcolor (Color.parsecolor ("#FFFFFF")); App.setroom (btn2.GetText (). toString ()); if (twofragment = = null) {twofragment = new twofragment (); Transaction.add (R.id.framelayout, twofragment);} else {trans
Action.show (twofragment);
Twofragment.mPullRefreshListView.setRefreshing (TRUE);
} break;
Case 2:btn3.setbackgroundcolor (Color.parsecolor ("#CFEFEF"));
Btn3.settextcolor (Color.parsecolor ("#FFFFFF"));
App.setroom (Btn3.gettext (). toString ()); if (threefragment = = null) {threefragment = new threefragment (); Transaction.add (R.id.framelayout, threefragment); else
{transaction.show (threefragment); threefragment.mPullRefreshListView.setRefreshing (true);} break;
Case 3:btn4.setbackgroundcolor (Color.parsecolor ("#CFEFEF"));
Btn4.settextcolor (Color.parsecolor ("#FFFFFF"));
App.setroom (Btn4.gettext (). toString ()); if (fourfragment = = null) {fourfragment = new fourfragment (); Transaction.add (R.id.framelayout, fourfragment);} else {T
Ransaction.show (fourfragment);
Fourfragment.mPullRefreshListView.setRefreshing (TRUE);
} break;
Default:break; } TransactIon.commit ();
/** * Clears all selected states. * * private void ClearSelection () {Btn1.setbackgroundcolor (Color.parsecolor ("#EFEFEF")); Btn1.settextcolor (
Color.parsecolor ("#234567"));
Btn2.setbackgroundcolor (Color.parsecolor ("#EFEFEF"));
Btn2.settextcolor (Color.parsecolor ("#234567"));
Btn3.setbackgroundcolor (Color.parsecolor ("#EFEFEF"));
Btn3.settextcolor (Color.parsecolor ("#234567"));
Btn4.setbackgroundcolor (Color.parsecolor ("#EFEFEF"));
Btn4.settextcolor (Color.parsecolor ("#234567"));
/** * All fragment are placed in a hidden state. * * @param transaction * The transaction to perform operations on fragment/private void Hidefragements (Fragmenttransaction transaction) {if Onefrag ment!= null) {transaction.hide (onefragment);} if (twofragment!= null) {transaction.hide (twofragment);} if (Threefrag
ment!= null) {transaction.hide (threefragment);} if (fourfragment!= null) {transaction.hide (fourfragment);}} }
Four fragment are similar, here is the first:
Package com.example.fragmentmytest;
Import java.util.ArrayList;
Import java.util.LinkedList;
Import java.util.List;
Import android.app.Activity;
Import Android.os.AsyncTask;
Import Android.os.Bundle;
Import android.support.v4.app.Fragment;
Import Android.util.Log;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.AdapterView;
Import Android.widget.ArrayAdapter;
Import Android.widget.AdapterView.OnItemClickListener;
Import Android.widget.ListView;
Import Com.example.adapter.MyAdapter;
Import Com.example.dao.ComputerRoomStatus;
Import Com.example.utils.ToastUtils;
Import Com.handmark.pulltorefresh.library.PullToRefreshBase;
Import Com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
Import Com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
Import Com.handmark.pulltorefresh.library.PullToRefreshListView; public class Onefragment extends Fragment {String room = ' 204 '; public pulltorefreshlistview Mpullrefreshlistview;
Private arrayadapter<string> Madapter;
private int mitemcount = 9;
Private linkedlist<string> Mlistitems;
Private Myadapter Madapter;
Private list<computerroomstatus> data; public view Oncreateview (Layoutinflater inflater, ViewGroup container, Bundle savedinstancestatus) {View view = Inflater.
Inflate (R.layout.twolayout, container, false);
Mpullrefreshlistview = (pulltorefreshlistview) view. Findviewbyid (r.id.pull_refresh_list_2);
Mpullrefreshlistview.setmode (Mode.pull_from_start);
return view; @Override public void onviewcreated (view view, Bundle savedinstancestate) {//TODO auto-generated a stub super.onv
iewcreated (view, savedinstancestate);
Initdatas ();
MAdapter1 = new Myadapter (getactivity (), data);
Madapter = new Myadapter (getactivity (), data, Room,mpullrefreshlistview);
Mpullrefreshlistview.setadapter (Madapter); Mpullrefreshlistview. Setonrefreshlistener (New onrefreshlistener2<listview> () {@Override public void OnpuLldowntorefresh (pulltorefreshbase<listview> refreshview) {log.e ("TAG", "Onpulldowntorefresh");//here Write down pull refresh task
New Getdatatask (). Execute (); @Override public void Onpulluptorefresh (pulltorefreshbase<listview> refreshview) {log.e ("TAG", "
Onpulluptorefresh ");
Here write pull load More tasks New Getdatatask (). Execute ();
}
});
Mpullrefreshlistview.setrefreshing (TRUE); private void Initdatas () {//INIT data and data Source = new arraylist<computerroomstatus> (); for (int i = 0; i < Mitemco Unt
i++) {Data.add (new Computerroomstatus (I, "1", "1", "3", "1", "1", "1"))} protected void AutoRefresh () {mpullrefreshlistview.setrefreshing (true);}//Request network interface, here is done fake data private class Getdatatask E Xtends asynctask<void, void, string> {@Override protected String doinbackground (void ... params) {try {//TODO parse J
Son Thread.Sleep (1000);
catch (Interruptedexception e) {} return "" + (mitemcount++);} @Override protected void OnPostExecute (String result) {//Data.add (New//Computerroomstatus (1, Result,result,result,result,result,result));
Data.add (new Computerroomstatus (Result), "", "", "3", "1", "1", "1"));
Madapter.notifydatasetchanged ();
Mpullrefreshlistview.onrefreshcomplete (); }
}
}
Myadapter
Package com.example.adapter;
Import java.util.List;
Import Android.content.Context;
Import Android.content.DialogInterface;
Import android.content.res.ColorStateList;
Import Android.graphics.Color;
Import Android.text.TextUtils;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.BaseAdapter;
Import Android.widget.Button;
Import Android.widget.TextView;
Import Com.example.dao.ComputerRoomStatus;
Import Com.example.dialog.CustomDialogOrder;
Import COM.EXAMPLE.FRAGMENTMYTEST.R;
Import Com.example.utils.ToastUtils;
Import Com.handmark.pulltorefresh.library.PullToRefreshListView; public class Myadapter extends Baseadapter {private context; private list<computerroomstatus> data; private
Layoutinflater Layoutinflater;
Private String Room;
Private Viewholder holder = null;
Private Pulltorefreshlistview Mpullrefreshlistview; Public Myadapter (context context, list<computerroomstatus> data, String room,pulltorefReshlistview mpullrefreshlistview) {this.context = context; this.data = data; this.room = room; this.mpullrefreshlistview
= Mpullrefreshlistview;
Layoutinflater = Layoutinflater.from (context); @Override public int GetCount () {return data.size ():} @Override public Object getitem (int position) {return Data.get (
position); @Override public long getitemid (int position) {return position;} @Override public view getview (int position, View conv Ertview, ViewGroup parent) {if (Convertview = null) {holder = new Viewholder (); Convertview = Layoutinflater.inflate (R.
Layout.lv_item, NULL);
Holder.seatid = (TextView) Convertview.findviewbyid (R.id.seatid);
Holder.time1 = (Button) Convertview.findviewbyid (r.id.time1);
Holder.time2 = (Button) Convertview.findviewbyid (r.id.time2);
Holder.time3 = (Button) Convertview.findviewbyid (R.ID.TIME3);
Holder.time4 = (Button) Convertview.findviewbyid (R.ID.TIME4);
Holder.time5 = (Button) Convertview.findviewbyid (R.ID.TIME5); Holder.time6 = (Button) converTview.findviewbyid (R.ID.TIME6);
Convertview.settag (holder);
else {holder = (Viewholder) Convertview.gettag ();}//Get the Entity class object in the collection final computerroomstatus s = data.get (position);
Holder.seatId.setText (S.getid () + "");
Holder.time1.setOnClickListener (new Lvbuttonlistener (position));
Holder.time2.setOnClickListener (new Lvbuttonlistener (position));
Holder.time3.setOnClickListener (new Lvbuttonlistener (position));
Holder.time4.setOnClickListener (new Lvbuttonlistener (position));
Holder.time5.setOnClickListener (new Lvbuttonlistener (position));
Holder.time6.setOnClickListener (new Lvbuttonlistener (position));
A little bit does not matter ... return convertview; Class Lvbuttonlistener implements View.onclicklistener {private int position; lvbuttonlistener (int pos) {position = PO
S @Override public void OnClick (View v) {switch (V.getid ()) {case R.id.time1:showdialog (position, "1");
D.time2:showdialog (Position, "2");
Break
Case R.id.time3:showdialog (Position, "3");
Break Case R.id.time4: ShowDialog (Position, "4");
Break
Case R.id.time5:showdialog (Position, "5");
Break
Case R.id.time6:showdialog (Position, "6");
Break
Default:break; }} public void ShowDialog (final int id, final String witch) {final Customdialogorder.builder Builder = new Customdialo
Gorder.builder (context);
Builder.settitle ("Appointment on the Machine"); Builder.setpositivebutton ("Appointment", new Dialoginterface.onclicklistener () {public void OnClick (Dialoginterface dialog, int which) {Dialog.dismiss ()///Submit when submitting application room and position and witch toastutils.mytoast (context, Room + ":" + ID + ":"
+ witch);
TODO concatenation string get to the specified interface//todo and refresh execution Drop-down flush mpullrefreshlistview.setrefreshing (TRUE);
}
}); Builder.setnegativebutton ("Cancel", new Android.content.DialogInterface.OnClickListener () {public void OnClick (
Dialoginterface dialog, int which) {Dialog.dismiss ();}});
Builder.create (). Show ();
} class Viewholder {TextView seatid;
Button time1, Time2, Time3, Time4, Time5, Time6; }
The above is a small set to introduce the Android imitation of today's headline simple refresh effect instance code knowledge, hope for everyone to help, if you have any questions welcome to my message, small series will promptly reply to everyone, and then thank you all for the cloud Habitat Community website support!