Android with Avatar User registration page

Source: Internet
Author: User

Detailed text can go to my Baidu experience to see: http://jingyan.baidu.com/article/cd4c2979eda109756e6e60de.html

The first is the layout of the registration page:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:paddingtop=" 20px "Android oid:orientation= "Horizontal" > <linearlayout android:id= "@+id/linearlayout1" android:orientation= "V        Ertical "android:layout_weight=" 2 "android:paddingleft=" 20px "android:layout_width=" Wrap_content "            android:layout_height= "Wrap_content" > <tablelayout android:id= "@+id/tablelayout1"                Android:layout_width= "Match_parent" android:layout_height= "wrap_content" > <tablerow Android:id= "@+id/tablerow1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" > <textview android:id= "@+id/textview1" Android:                    Textsize= "20px"Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:tex t= "User name:"/> <edittext android:id= "@+id/user" android:minwidth= " 400px "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "/&gt            ; </TableRow> <tablerow android:id= "@+id/tablerow2" android:layout_width= " Wrap_content "android:layout_height=" Wrap_content "> <textview Android                    Oid:id= "@+id/textview2" android:textsize= "20px" android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Password:"/> <edi Ttext android:id= "@+id/pwd" android:inputtype= "Textpassword" Android Oid:layout_Width= "Wrap_content" android:layout_height= "wrap_content"/> </TableRow>                <tablerow android:id= "@+id/tablerow3" android:layout_width= "Wrap_content"                    android:layout_height= "Wrap_content" > <textview android:id= "@+id/textview3" Android:textsize= "20px" android:layout_width= "Wrap_content" android:l ayout_height= "Wrap_content" android:text= "Confirm password:"/> <edittext A Ndroid:id= "@+id/repwd" android:inputtype= "Textpassword" android:layout_width= "Wrap_c                 Ontent "android:layout_height=" wrap_content "/> </TableRow> <tablerow Android:id= "@+id/tablerow4" android:layout_width= "Wrap_content" Android:layo ut_height= "Wrap_content" > <textview android:id= "@+id/textview4" android:textsize= "20px                    "Android:layout_width=" wrap_content "android:layout_height=" Wrap_content "                    android:text= "e-mail address:"/> <edittext android:id= "@+id/email" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"/> < /tablerow> </TableLayout> </LinearLayout> <linearlayout android:id= "@+id/linearlayou T2 "android:orientation=" vertical "android:gravity=" center_horizontal "android:layout_width=" Wrap_con Tent "android:layout_weight=" 1 "android:layout_height=" wrap_content "> <imageview an Droid:id= "@+id/imageview1" android:layout_width= "158px" android:layout_height= "150px" and roid:src= "@drawable/ic_lAuncher "/> <button android:id=" @+id/button1 "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:text= "select Avatar"/> </linearlayout></linearlayout& Gt

Then is the page layout of the library, by the user to select the picture, here I use a few photos inside the Windows system

<?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"> <GridView android:layout_width="wrap_content"Android:layout_height="match_parent"Android:id="@+id/gridview"Android:numcolumns="4"/></linearlayout>

Then our activity on the registration page writes the following code:

Button button1=(Button) Findviewbyid (R.id.button1); Button1.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Intent Intent=NewIntent (mainactivity. This, Headactivity.class); Startactivityforresult (Intent,0x11); }}); @Override Onactivityresult method:protected voidOnactivityresult (intRequestcode,intresultcode,intent data)        {Super.onactivityresult (requestcode,resultcode,data); if(requestcode==0x11&&requestcode==0x11) {Bundle bundle=Data.getextras (); intImageid=bundle.getint ("imageId"); ImageView ImageView=(ImageView) Findviewbyid (R.ID.IMAGEVIEW1);        Imageview.setimageresource (IMAGEID); }    }

Click the button to jump to the gallery activity page.

In the gallery activity, write the following code in response to the user clicking on the image and passing it through intent to the previous activity:

GridView gridview= (GridView) Findviewbyid (R.id.gridview); Baseadapter adapter=new Baseadapter () {@Override public int getcount () {return imag            Eid.length;            } @Override public Object getItem (int position) {return position;            } @Override public long getitemid (int position) {return position; } @Override public View getView (int position, view Convertview, ViewGroup parent) {I                Mageview ImageView;                    if (convertview==null) {imageview=new imageView (headactivity.this);                    Imageview.setadjustviewbounds (TRUE);                    Imageview.setmaxheight (58);                    Imageview.setmaxwidth (50);                Imageview.setpadding (5,5,5,5);                }else{imageview= (ImageView) Convertview; } imageview.seTimageresource (Imageid[position]);            return imageView;        }        };        Gridview.setadapter (adapter); Gridview.setonitemclicklistener (New Adapterview.onitemclicklistener () {@Override public void Onitem                Click (adapterview<?> Parent, view view, int position, long id) {Intent intent=getintent ();                Bundle Bundle=new Bundle ();                Bundle.putint ("ImageId", Imageid[position]);                Intent.putextras (bundle);                Setresult (0x11,intent);            Finish (); }        });

The results are as follows:

Android with Avatar User registration page

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.