栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

个人中心界面

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

个人中心界面




    
    

    
        
            
            
        
        
        
            
            
        
        
        
            
            
        
        

        
            
            
        
        

    
    
        

 

 

MyFragmeny.java文件中这样写

 public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        homeViewModel =
                new ViewModelProvider(this).get(HomeViewModel.class);
        root = inflater.inflate(R.layout.fragment_my, container, false);
        initView();

        user = getActivity().getSharedPreferences("user", Context.MODE_PRIVATE);
        if (login==0)Login(); {
         myLogin.setOnClickListener(v -> {
             if (login==0) {
                 Login();
             }else if(login==1){
                 login = 0;
                 SharedPreferences.Editor editor=user.edit();
                 editor.putString("username","");
                 editor.putString("password","");
                 editor.putString("token","");
                 editor.putString("userId","");
                 editor.apply();
                 startActivity(new Intent(getContext(),My_LoginActivity.class));

             }

         });

            myGerenxinxi.setOnClickListener(v -> {
                if (login==0){
                    Login();
                }else {
                    startActivity(new Intent(getContext(),My_LoginActivity.class));

                }
            });
            myDingdanliebiao.setOnClickListener(v -> {
                if (login==0){
                    Login();
                }else {
                    startActivity(new Intent(getContext(),My_LoginActivity.class));

                }
            });
            myXiugaimima.setOnClickListener(v -> {
                if (login==0){
                    Login();
                }
                else {
                    startActivity(new Intent(getContext(),My_LoginActivity.class));

                }

            });
            myTijiaofankui.setOnClickListener(v -> {
                if (login==0){
                    Login();
                }else {
                    startActivity(new Intent(getContext(),My_LoginActivity.class));

                }
            });
        }
        return root;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (login==0){
            myLogin.setText("登录");
        }else {
            myLogin.setText("退出账号");
            getMyUserInfoData();

        }
    }
//   用户信息
    private void getMyUserInfoData() {
        RetrofitClient.apiService().getUserInfoData(user.getString("token","")).enqueue(new Callback() {
            @Override
            public void onResponse(Call call, Response response) {
                MyUserInfoBean body = response.body();
                if (body!=null&&body.getCode()==200) {
                    MyUserInfoBean.UserBean user = body.getUser();
//                    回传一个用户名
                    myWeidenglu.setText(user.getNickName());
//                    if (!user.getAvatar().equals("")){
//                        Glide.with(getActivity()).load(RetrofitClient.IP+user.getAvatar())
//                                .centerCrop()
//                                .into()
//                    }

                }
            }

            @Override
            public void onFailure(Call call, Throwable throwable) {

            }
        });


            }





    //    登录状态
    private void Login() {
        Toast.makeText(getContext(),"尚未登录",Toast.LENGTH_SHORT).show();
        startActivity(new Intent(getContext(), My_LoginActivity.class));
    }

    private void initView() {


        myTouxiang = (ImageView) root.findViewById(R.id.my_touxiang);
        myWeidenglu = (TextView) root.findViewById(R.id.my_weidenglu);
        myGerenxinxi = (LinearLayout) root.findViewById(R.id.my_gerenxinxi);
        myDingdanliebiao = (LinearLayout)root. findViewById(R.id.my_dingdanliebiao);
        myXiugaimima = (LinearLayout) root.findViewById(R.id.my_xiugaimima);
        myTijiaofankui = (LinearLayout) root.findViewById(R.id.my_tijiaofankui);
        myLogin = (Button) root.findViewById(R.id.my_login);

    }
}

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/885198.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号