This example for you to share the Android imitation Sina Weibo paging management interface of the specific code for your reference, the specific content as follows
Multiple activity paging management, in order to facilitate access to the context, the use of inherited tabactivity traditional methods.
General idea: Use Radiogroup click to trigger different card items, select card items to bind different activiity, and then paging management. See note for detailed explanation.
/** * Main activity * Switch different interfaces by clicking RadioButton under Radiogroup * Created by D&ll on 2016/7/20.
* * public class Mainactivity extends tabactivity {//Definition Tabhost object private tabhost tabhost;
Define Radiogroup object Private Radiogroup Radiogroup;
public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (r.layout.tab_layout);
Initview ();
InitData ();
/** * Initialize component/private void Initview () {//Instantiate tabhost, get Tabhost object tabhost = Gettabhost ();
Gets the number of activity int count = Constant.ConValue.mTabClassArray.length; for (int i = 0; i < count; i++) {//Set the icon, text, and content for each tab button Tabspec Tabspec = Tabhost.newtabspec (Constant.ConValue.mT
Extviewarray[i]). Setindicator (Constant.convalue.mtextviewarray[i]). SetContent (Gettabitemintent (i));
Add the tab button to the Tab tab in Tabhost.addtab (Tabspec);
}//Instantiate Radiogroup Radiogroup = (radiogroup) Findviewbyid (R.id.main_radiogroup); /** * Initialization component */private void InitData () {//To RadiogroUp setting Listener Event Radiogroup.setoncheckedchangelistener (new Oncheckedchangelistener () {public void oncheckedchanged (RadioGro Up group, int checkedid) {switch (checkedid) {case R.id.radiobutton0:tabhost.setcurrenttabbytag (Constant .
Convalue.mtextviewarray[0]);
Break
Case R.id.radiobutton1:tabhost.setcurrenttabbytag (constant.convalue.mtextviewarray[1]);
Break
Case R.id.radiobutton2:tabhost.setcurrenttabbytag (constant.convalue.mtextviewarray[2]);
Break
Case R.id.radiobutton3:tabhost.setcurrenttabbytag (constant.convalue.mtextviewarray[3]);
Break
Case R.id.radiobutton4:tabhost.setcurrenttabbytag (constant.convalue.mtextviewarray[4]);
Break
}
}
});
((RadioButton) radiogroup.getchildat (0)). Toggle (); /** * to Tab TAB set content (each content is an activity)/private Intent gettabitemintent (int index) {Intent Intent = new Intent (t
His, constant.convalue.mtabclassarray[index]);
return intent;
}
}
The
mainactivity layout file tab_layout.xml. Tabhost layout, add a tabwidget to display the activity, below is a button menu that shows the radiogroup to toggle the activity.
<?xml version= "1.0" encoding= "Utf-8"?> <tabhost xmlns:android= "Http://schemas.android.com/apk/res/android" "Android:id=" @android: Id/tabhost "android:layout_width=" fill_parent android:layout_height= "fill_parent" > &L T LinearLayout android:layout_width= "fill_parent" android:layout_height= fill_parent "android:orientation=" vertical "> <framelayout android:id=" @android: Id/tabcontent "android:layout_width=" Fill_parent "Android:layout_hei" ght= "0.0dip" android:layout_weight= "1.0"/> <tabwidget android:id= "@android: Id/tabs" android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_weight= "0.0" android:visibility= "Gone"/> & Lt Radiogroup android:id= "@+id/main_radiogroup" android:layout_width= fill_parent "android:layout_height=" Wrap_conte NT "android:layout_gravity=" Bottom "android:background=" @drawable/tab_widget_background "android:gravity=" Center_ Vertical "Android:orientation= "Horizontal" android:padding= "2dip" > <radiobutton android:id= "@+id/radiobutton0" style= "@style/tab
_item_background "android:drawabletop=" @drawable/tab_home "android:text=" Home "android:textcolor=" #ffffff "/> <radiobutton android:id= "@+id/radiobutton1" style= "@style/tab_item_background" android:drawabletop= "@dra Wable/tab_msg "android:text=" comment "android:textcolor=" #ffffff "/> <radiobutton android:id=" @+id/RadioBut Ton2 "style=" @style/tab_item_background "android:drawabletop=" @drawable/tab_write "android:text=" Hair Weibo "Andr
Oid:textcolor= "#ffffff"/> <radiobutton android:id= "@+id/radiobutton3" style= "@style/tab_item_background"
android:drawabletop= "@drawable/tab_me" android:text= "User Information" android:textcolor= "#ffffff"/> <radiobutton
Android:id= "@+id/radiobutton4" style= "@style/tab_item_background" android:drawabletop= "@drawable/tab_more"
android:text= "More"Android:textcolor= "#ffffff"/> </RadioGroup> </LinearLayout> </TabHost>
Effect Chart:
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.