Place profile photo in Nav_header

Asked

Viewed 680 times

1

I have a question in creating an App.

I need to put the user profile photo in my Nav_header_tela_princial.

inserir a descrição da imagem aqui

I already have a profile screen, but I need to use the same image of the user profile screen for my NAV.

inserir a descrição da imagem aqui

The profile screen is working correctly, I can save the image, but I only need to use the same Uri on the other screen.

I haven’t been able to create any code yet because I have no idea what to research. I need a light on how to accomplish this.

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings);

    Bundle bundle = new Bundle();
    bundle.putString("foto", resultUri.toString());
    Intent intent = new Intent(SettingsActivity.this, TelaPrincipalActivity.class);
    intent.putExtras(bundle);
    startActivity(intent);

    edtNameField = (EditText) findViewById(R.id.edtName);
    edtPhoneField = (EditText) findViewById(R.id.edtPhone);

    imgProfileImage = (ImageView) findViewById(R.id.imgProfileImage);

    btnBack = (Button) findViewById(R.id.btnBack);
    btnConfirm = (Button) findViewById(R.id.btnConfirm);

    mAuth = FirebaseAuth.getInstance();
    userID = mAuth.getCurrentUser().getUid();
    mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(userID);

    getUserInfo();

    imgProfileImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType("image/*");
            startActivityForResult(intent, 1);
        }
    });

This would be the Activity that should receive the data from Uri.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tela_principal);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();

    String foto = bundle.getString("foto");

    btnTest = (Button) findViewById(R.id.BtnTest);
    btnTest.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openBtnTest();
        }
    });

    edtSearch = (TextView) findViewById(R.id.edtSearch);

    edtSearch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            search();
        }
    });
  • Your question is very shallow. Your doubt is how to recover the image? How to present it inside the ImageView?

  • If it is for how to recover the image, you must specify where you are saving it. So, it is easier to help you

1 answer

0

If what you want is to use the database photo to display in Nav_header_photo you will need to rescue this Url from the database, and this is done according to your application. Here is an example of how to rescue a database value (in this case Firebase Realtime Database) to display when loading Activity (loading into Activity’s Oncreate method):

getDados Also has the example of creating user.

Now, if you only wish to pass information from one Activity to another and I suppose you know something about manipulating the elements of the View (the R.id.findViewById and etc...)

You can send the data you want through Bundle.

Just adapt this example in some event in the class of your Activity, where urlFoto is the variable already with the url and the Intent is used to make the transition between activities:

 Bundle bundle = new Bundle();
 bundle.putString("foto", urlfoto.toString());

 Intent intent = new Intent(activityAtual.this, proximaActivity.class);
 intent.putExtras(bundle);

 startActivity(intent);

Now in the next Activity.java you redeem the values with the following code:

 Intent intent = getIntent();
 Bundle bundle = intent.getExtras();

 String foto = bundle.getString("foto");

Just use your url and set it in the View widget you want.

  • The idea is just to pass the information of my Settingsactivity that has an imageView with the profile photo of the user to my Activityprincipal that tbm has an Imageview, however this will only receive the data.

  • For this you should take the Url of the database and put in Imageview as I said in the reply, please clarify what is the difficulty so that we can help you.

  • So Jhow tried to do as you mentioned, but the crash app. I need to create new methods or just play on Oncreate ? I edited my question and added what you mentioned, please validate if it would be so anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.