day18
我的页面功能实现
目前主要是实现三个地方的跳转监听事件
package Home; import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.Fragment; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.expressdelivery.R; import Home.Data.User; import Home.http.Contants; import Home.login.LoginActivity; import Home.login.LoginActivity2; import de.hdodenhof.circleimageview.CircleImageView; /** * A simple {@link Fragment} subclass. * create an instance of this fragment. */ public class MyFragment extends Fragment { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; private CircleImageView mImageHead; private Button button; private TextView textView1; private TextView textView2; private TextView textView3; private TextView textView4; private TextView textView5; public MyFragment() { // Required empty public constructor } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view=inflater.inflate(R.layout.fragment_my, container, false); textView1=view.findViewById(R.id.txt_username); textView2=view.findViewById(R.id.txt_my_orders); textView3=view.findViewById(R.id.txt_my_car); textView4=view.findViewById(R.id.txt_my_address); textView5=view.findViewById(R.id.txt_my_msg); button=view.findViewById(R.id.btn_logout); mImageHead=view.findViewById(R.id.img_head); //User user = CniaoApplication.getInstance().getUser(); //showUser(user); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(getActivity(), LoginActivity2.class); startActivityForResult(intent, Contants.REQUEST_CODE); } }); mImageHead.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(getActivity(), LoginActivity2.class); startActivityForResult(intent, Contants.REQUEST_CODE); } }); textView1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(getActivity(), LoginActivity2.class); startActivityForResult(intent, Contants.REQUEST_CODE); } }); return view; } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { User user = CniaoApplication.getInstance().getUser(); showUser(user); } private void showUser(User user){ if(user!=null){ if(!TextUtils.isEmpty(user.getLogo_url())) showHeadImage(user.getLogo_url()); textView1.setText(user.getUsername()); button.setVisibility(View.VISIBLE); } else { textView1.setText(R.string.to_login); button.setVisibility(View.GONE); } } private void showHeadImage(String url){ Glide.with(this) .load(url) .into(mImageHead); } }