个人资料界面以及 数据的显示以及修改

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.l.instructordome.Edit_presonActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/white"
        android:padding="0dp">


        <ImageButton
            android:id="@+id/back_btn"
            android:layout_width="?attr/actionBarSize"
            android:layout_height="?attr/actionBarSize"
            android:layout_alignParentLeft="true"
            android:background="@drawable/tab_menu_bg"
            android:onClick="editInfoBackTo"
            android:src="?attr/homeAsUpIndicator"
            />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="修改个人信息"
            android:textSize="19sp" />

    </RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0.29"
                android:orientation="vertical"
                android:weightSum="1">

                <ImageView
                    android:id="@+id/head_icon"
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:layout_marginLeft="140dp"
                    android:layout_marginTop="12dp"
                    android:scaleType="fitCenter"
                    app:srcCompat="@mipmap/t0"/>

                <Button
                    android:id="@+id/button_changeimg"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:background="@null"
                    android:elevation="4dp"
                    android:onClick="editHeadIcon"
                    android:text="修改头像"
                    android:textColor="@color/blue"
                    android:textSize="17sp"/>

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginTop="20dp"
                android:background="@color/white"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="昵称"
                    android:textSize="17sp"/>

                <EditText
                    android:id="@+id/byname"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"
                    android:text="江南"
                    android:textSize="17sp"/>
            </LinearLayout>

            <View
                android:id="@+id/view"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView21"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="学号"
                    android:textSize="17sp"/>

                <EditText
                    android:id="@+id/username"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"
                    android:text="16051029"
                    android:textSize="17sp"/>
            </LinearLayout>

            <View
                android:id="@+id/view2"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginTop="2dp"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="2.04"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="性别"
                    android:textSize="17sp"/>

                <Spinner
                    android:id="@+id/sex"
                    android:layout_width="270dp"
                    android:layout_height="match_parent"
                    android:entries="@array/sex"
                    android:orientation="horizontal"
                    android:paddingLeft="10dp"
                    />


            </LinearLayout>

            <View
                android:id="@+id/view3"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="邮箱"
                    android:textSize="17sp"
                    />

                <EditText
                    android:id="@+id/email"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:inputType="textEmailAddress"
                    android:paddingLeft="10dp"
                    android:text="[email protected]"
                    android:textSize="17sp"/>


            </LinearLayout>

            <View
                android:id="@+id/view4"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="学院"
                    android:textSize="17sp"
                    />

                <EditText
                    android:id="@+id/collage"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:inputType="textEmailAddress"
                    android:paddingLeft="10dp"
                    android:text="信息科学与技术"
                    android:textSize="17sp"/>


            </LinearLayout>

            <View
                android:id="@+id/view5"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/textView12"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="专业"
                    android:textSize="17sp"
                    />

                <EditText
                    android:id="@+id/major"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:inputType="textEmailAddress"
                    android:paddingLeft="10dp"
                    android:text="计算机科学与技术"
                    android:textSize="17sp"/>


            </LinearLayout>

            <View
                android:id="@+id/view6"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="电话"
                    android:textSize="17sp"
                    />


                <EditText
                    android:id="@+id/tele"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:inputType="phone"
                    android:paddingLeft="10dp"
                    android:text="16642712339"
                    android:textSize="17sp"/>


            </LinearLayout>

            <View
                android:id="@+id/view7"
                style="@style/bg_line"
                android:layout_width="wrap_content"
                android:layout_height="2px"
                android:layout_weight="0.29"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="宿舍"
                    android:textSize="17sp"/>


                <EditText
                    android:id="@+id/dnumber"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"
                    android:text="1434"
                    android:textSize="17sp"/>


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginTop="20dp"
                android:background="@color/white"
                android:orientation="horizontal">


                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="20dp"
                    android:text="个性签名"
                    android:textSize="17sp"/>


                <EditText
                    android:id="@+id/says"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:hint="介绍下自己吧"
                    android:paddingLeft="10dp"
                    android:textSize="17sp"/>


            </LinearLayout>

            <Button
                android:id="@+id/p_sub"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginBottom="10dp"
                android:background="@color/colorPrimary"
                android:onClick="editInfoPost"
                android:padding="8dp"
                android:text="提交"
                android:textAlignment="center"
                android:textColor="@color/white"
                android:textSize="16sp"/>
        </LinearLayout>


    </ScrollView>


</LinearLayout>

数据显示

    private void initview() {
        MyUser userInfo = BmobUser.getCurrentUser(MyUser.class);
        String t_name=userInfo.getByname();
        byname=(EditText)findViewById(R.id.byname);
        byname.setText(t_name);

        username=(EditText)findViewById(R.id.username);
        String t_username=userInfo.getUsername();
        username.setText(t_username);

        String t_email=userInfo.getEmail();
        email=(EditText)findViewById(R.id.email);
        email.setText(t_email);

        String t_collage=userInfo.getCollege();
        collage=(EditText)findViewById(R.id.collage);
        collage.setText(t_collage);

        major=(EditText)findViewById(R.id.major);
        String t_major=userInfo.getMajor();
        major.setText(t_major);

        tele=(EditText)findViewById(R.id.tele);
        String t_tele=userInfo.getMobilePhoneNumber();
        tele.setText(t_tele);

        bnumber=(EditText)findViewById(R.id.dnumber);
        String t_bnum=userInfo.getDnumber();
        bnumber.setText(t_bnum);

        says =(EditText)findViewById(R.id.says);
        String t_says=userInfo.getSays();
        says.setText(t_says);


        sex=(Spinner)findViewById(R.id.sex);
        int sexCount=userInfo.getSex();
        sex.setSelection(sexCount,true);

        p_sbmit=(Button)findViewById(R.id.p_sub);
        p_sbmit.setOnClickListener(this);

        back_btn=(ImageButton)findViewById(R.id.back_btn);
        back_btn.setOnClickListener(this);

        button_changeimg=(Button)findViewById(R.id.button_changeimg);
        button_changeimg.setOnClickListener(this);

    }

数据修改

  private void edit_person() {
       MyUser newUser = new MyUser();
        String s_byname = byname.getText().toString();
        newUser.setByname(s_byname);

        int sexx;
        String s_sex=sex.getSelectedItem().toString();
        if (s_sex.equals("男"))
        {
            sexx=0;
        }else {
            sexx=1;
        }
        newUser.setSex(sexx);

        String s_email = email.getText().toString();
        newUser.setEmail(s_email);

        String s_college = collage.getText().toString();
        newUser.setCollege(s_college);

        String s_major = major.getText().toString();
        newUser.setMajor(s_major);

        String s_tele = tele.getText().toString();
        newUser.setMobilePhoneNumber(s_tele);

        String s_dnum = bnumber.getText().toString();
        newUser.setDnumber(s_dnum);

        String s_says = says.getText().toString();
        newUser.setSays(s_says);

        MyUser bmobUser = MyUser.getCurrentUser(MyUser.class);
        newUser.update(bmobUser.getObjectId(), new UpdateListener() {
            @Override
            public void done(BmobException e) {
                if (e == null) {
                    Log.i("smile", "用户更新成功");
                    SYSDiaLogUtils.showSuccessDialog(Edit_presonActivity.this, "个人信息修改成功", "恭喜你,操作成功了!", "OK", false);
                } else {
                    SYSDiaLogUtils.showErrorDialog(Edit_presonActivity.this, "失败警告", "很抱歉,这次更新失败,請检查网络重新試試!", "取消", false);
                    Log.i("smile", "用户更新失败");
                }
            }
        });

    }

我觉的逻辑挺简单的 ,可是好麻烦啊 记得好像有个框架的,可以简写 findViewById 不记得,等有时间一定找一下

这里我写的时候出现了问题,

newUser.update(bmobUser.getObjectId(), new UpdateListener() {

获取对象 一定要有识别改行数据 就想select 语句 点有where 吧 个人 全是瞎想,之前我就没放学号这个显示 ,就无法匹配插入失败。

还有Spinner 这个 数据的显示问题,这里是我个人解决的办法的 sex 对象 ,不知道有没有其他函数可以解决这个问题 本来sex 我的 Boolean,但是我无法识别,获取的对象 我就是无法对象 用String 也不能自己 像EditText 一些 getText() setText(),于是我用了这种方法 ,不知道广大人群有什么高级写法,对我来说 ,能用就好。

number sex;  // 0 ,男; 1,女;

插入:

int sexx;
String s_sex=sex.getSelectedItem().toString();
if (s_sex.equals("男"))
{
    sexx=0;
}else {
    sexx=1;
}
newUser.setSex(sexx);

读:

sex=(Spinner)findViewById(R.id.sex);
int sexCount=userInfo.getSex();
sex.setSelection(sexCount,true);

这里的警示框,用的已经集成的框架 GitHub的 就按照上面走,没错,好用 ,不用自己写,特别喜欢开源框架,表示感谢,可以少写很多。

https://github.com/fingerth/FingerthAndroidUtils

头像这里我并没有写,因为我还没有写到头像上传等 ,之后头像我会写拍照和从相册里选择。等我写的时候会单独写一篇文。先完善全部界面之后,在细化功能。

发布了29 篇原创文章 · 获赞 22 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_39131246/article/details/89495987