Android Project Weiyi Address Book (i)

Source: Internet
Author: User

Long time no blog, these days are busy looking for work and no time to write a blog, this week want to take a break to do this small project, when the practice

It's in the wee hours of the morning, blogging, hoping to help people who need it.

Let's talk about the function of the project. There are contact lists, call logs, SMS records, settings. May later add some features, this project mainly use similar UI effect, personally feel good OH

You used a custom control in your contact list, and so on.

-----------Welcome to join the Exchange group 386451316 have a question.

Please specify the reprint address so late to write not easy AH

Let's take a look. This is the first module that will continue to be updated


Today first introduced Fragment+radiobutton replacement tabhost seems to be the most popular mode,

Next introduce the layout to see the picture


Activity_main.xml file

<relativelayout xmlns:andactivity_main.xmlroid= "http://schemas.android.com/apk/res/android" xmlns:tools= "http ://schemas.android.com/tools "android:layout_width=" match_parent "android:background=" #FFF "android:layout_height = "Match_parent" > <android.support.v4.view.viewpager android:id= "@+id/pager" android:layout_width= " Fill_parent "android:layout_height=" wrap_content "android:layout_above=" @+id/titlelayout "> </andro id.support.v4.view.viewpager> <linearlayout android:id= "@+id/titlelayout" Android:layout_width= "fil L_parent "android:layout_height=" Wrap_content "android:layout_alignparentbottom=" true "> <Radio Group android:id= "@+id/tab_menu" android:layout_width= "Fill_parent" android:layout_height            = "Wrap_content" android:background= "@drawable/tab_bg_normal" android:orientation= "Horizontal" >      <radiobutton          Android:id= "@+id/title1" style= "@style/tab_style" android:checked= "true" android:drawabletop= "@drawable/tab_activity_selector" android:text= "Contacts"/> <radiobu Tton android:id= "@+id/title2" style= "@style/tab_style" android:drawabletop= "@ Drawable/tab_activity_selector "android:text=" Call history/> <framelayout Android                    : layout_width= "wrap_content" android:layout_height= "wrap_content" > <radiobutton Android:id= "@+id/title3" style= "@style/tab_styles" Android:drawablebot tom= "@drawable/tab_activity_selector"/> </FrameLayout> <radiobutton Android Oid:id= "@+id/title4" style= "@style/tab_style" android:drawabletop= "@drawable/tab_activity_se Lector "Android:text= "SMS"/> <radiobutton android:id= "@+id/title5" style= "@style/tab        _style "android:drawabletop=" @drawable/tab_activity_selector "android:text=" Settings "/> </RadioGroup> </LinearLayout></RelativeLayout>

Each page of the file

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "><textviewandroid:id=" @+ Id/tv_tab4 "android:layout_width=" fill_parent "android:layout_height=" match_parent "android:text=" Information List "Android: Textsize= "28SP"/></relativelayout>

The above is the layout of the document can be read the basis of the fact that this issue is the basis

Package Com.zw.weiyi.phonesms;import Java.util.arraylist;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.support.v4.view.pageradapter;import Android.support.v4.view.viewpager;import Android.support.v4.view.viewpager.onpagechangelistener;import Android.view.keyevent;import Android.view.motionevent;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.radiobutton;import Android.widget.toast;import Com.zw.weiyi.fragment.callfragment;import Com.zw.weiyi.fragment.infofragment;import Com.zw.weiyi.fragment.settingfragment;import Com.zw.weiyi.fragment.smsfragment;import com.zw.weiyi.util.myapplication;/** * * @author STRIVER_ZW * Date 2014-11-19 */public class Mainactivity extends BaseA Ctivity implements Onpagechangelistener {private Viewpager pager;private pageradapter madapter;private ArrayList< fragment> fragments;private arraylist<radiobutton> title = new Arraylist<radiobutton> ();//4 titles// Dial Button Private RadiObutton bu; @Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);///slidingmenu inside rewrite Initview ();//Initialize control inittitle (); Initviewpager (); Bu.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {toast.maketext (Mainactivity.this, "Middle", 1). Show ();}}); /** * Initialize view */private void Initview () {bu = (RadioButton) Findviewbyid (r.id.title3);p ager = (Viewpager) Findviewbyid (r.id. pager);//Initialize control fragments = new arraylist<fragment> ();//Initialize Data Fragments.add (new Infofragment (this)); Fragments.add (New Callfragment ());//fragments.add (new Phonefragment ()); Fragments.add (new Smsfragment ()); Fragments.add (New Settingfragment (This));} /** * Initialize Viewpager */private void Initviewpager () {madapter = new Myviewpageradapter (Getsupportfragmentmanager (), Fragments);p Ager.setadapter (madapter);p Ager.setonpagechangelistener (This);p ager.setcurrentitem (0);//set to the current first}/ * * Initialize several radiobutton */private void Initti to display the titleTle () {Title.add ((RadioButton) Findviewbyid (r.id.title1));//Three title Tags Title.add ((RadioButton) Findviewbyid ( R.id.title2)//title.add ((RadioButton) Findviewbyid (R.id.title3)); Title.add ((RadioButton) Findviewbyid ( R.ID.TITLE4) Title.add ((RadioButton) Findviewbyid (r.id.title5)); Title.get (0). Setonclicklistener (New Myonclicklistener (0));//Set Response Title.get (1). Setonclicklistener (New Myonclicklistener (1)); Title.get (2). Setonclicklistener (New Myonclicklistener (2)), Title.get (3). Setonclicklistener (New Myonclicklistener (3));} /** * Rewrite onclicklistener response function, the main purpose is to achieve click on the title, pager will follow the response switch * * @author * */private class Myonclicklistener implements O Nclicklistener {private int index;public myonclicklistener (int index) {this.index = index;} @Overridepublic void OnClick (view v) {Pager.setcurrentitem (index);//Viewpager The view of the past, the realization of the false title and pager linkage Title.get ( Index). setchecked (true);//settings are selected, otherwise the background of the layout does not switch}}/** * The following three are Onpagechangelistener interface functions */@Overridepublic void onpagescrollstatechanged (int arg0) {} @OverridepubLIC void onpagescrolled (int arg0, float arg1, int arg2) {} @Overridepublic void onpageselected (int arg0) {title.get (arg0). s Etchecked (TRUE);//Keep page and button linkage}//record number of exits protected int dfilnish=0;//intercept Touch Event @overridepublic Boolean dispatchtouchevent ( Motionevent ev) {dfilnish=0;//0 mistakenly processed return super.dispatchtouchevent (EV);} @Overridepublic boolean onKeyUp (int keycode, keyevent event) {if (keycode==keyevent.keycode_back) {//fallback key dfilnish++;if ( Dfilnish==1) {Toast.maketext (this, "Click again to exit", Toast.length_long). Show (); else if (Dfilnish ==2) {myapplication.getinstance (). AppExit ();//super.finish ();} return true;} Return Super.onkeyup (KeyCode, event);}}
The above code has comments should not be difficult

Java code for each page

Package Com.zw.weiyi.fragment;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Com.zw.weiyi.phonesms.R ;p ublic class Phonefragment extends Fragment {@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate);} @Overridepublic View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {View view = I Nflater.inflate (R.layout.phone_fragment, container, false);//The Rootview of the cache needs to determine if it has been added to the parent, and if any parent needs to be removed from the parent, Otherwise it would have happened illegalstateexception. ViewGroup parent = (ViewGroup) view.getparent (); if (parent! = null) {Parent.removeview (view);} return view;}}

Use adapter Fragmentpageradapter to load inside and see the code.

Package Com.zw.weiyi.phonesms;import Java.util.arraylist;import Android.support.v4.app.fragment;import Android.support.v4.app.fragmentmanager;import android.support.v4.app.fragmentpageradapter;/** * This adapter has fragment array * @author STRIVER_ZW *   Date  2014-11-19 */public class Myviewpageradapter extends Fragmentpageradapter {Private arraylist<fragment> fragments;//need to be added to the above Fragmentpublic Myviewpageradapter ( Fragmentmanager FM) {super (FM);} /** * Custom Constructors * @param FM * @param fragments arraylist<fragment> */public myviewpageradapter (Fragmentmanager fm,Arr Aylist<fragment> fragments) {super (FM); this.fragments = fragments;} @Overridepublic Fragment getItem (int arg0) {return fragments.get (arg0);//Return Fragment object} @Overridepublic int GetCount () { return fragments.size ();//Returns the number of fragment}}

I'm going to be here today, let's set up the frame.

Android Project Weiyi Address Book (i)

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.