• 7
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Navigator drawer header picture does not set in my Firebase query. It does not give an error but it does not show the load picture.

Kotlin;

val navigationView = findViewById(R.id.nav_view) as NavigationView
        val headerview = navigationView.getHeaderView(0)
        var imageViewUser = headerview.imgUserProfilNav as ImageView
        mUserAuthListener = object : FirebaseAuth.AuthStateListener {
            override fun onAuthStateChanged(p0: FirebaseAuth) {
                var kullanici = p0.currentUser
               //  Glide.with(this@ProfilNavMenu).load(R.drawable.ic_action_user).into(imageViewUser)
                headerview.imgUserProfilNav.setImageResource(R.drawable.ic_action_user)
                if (kullanici != null) {
                   // Picasso.with(this@ProfilNavMenu).load(R.drawable.ic_action_user).fit().centerCrop().into(headerview.imgUserProfilNav)

                }
            }
        }

ProfileNavMenu - nav_header_profil_nav_menu.xml ;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imgUserProfilNav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/nav_header_desc"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="@string/nav_header_title"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nav_header_subtitle" />

</LinearLayout>

How can I set the picture with Kotlin and Firebase? I have even tried with Glide but still it didn't show any picture of url or drawable pictures.

Instead of this:

mUserAuthListener = object : FirebaseAuth.AuthStateListener {
            override fun onAuthStateChanged(p0: FirebaseAuth) {
                var kullanici = p0.currentUser
               //  Glide.with(this@ProfilNavMenu).load(R.drawable.ic_action_user).into(imageViewUser)
                headerview.imgUserProfilNav.setImageResource(R.drawable.ic_action_user)
                if (kullanici != null) {
                   // Picasso.with(this@ProfilNavMenu).load(R.drawable.ic_action_user).fit().centerCrop().into(headerview.imgUserProfilNav)

                }
            }
        }

Try this:

 mUserAuthListener = object : FirebaseAuth.AuthStateListener {
            override fun onAuthStateChanged(p0: FirebaseAuth) {

           Toast.makeText(getContext(), "Set Image here", Toast.LENGTH_SHORT).show();
                }
            }
        }

This will help you if your onAuthStatChanged is running each time or not. If it's not running each time you will have to usdifferentce approach.

Finally the running code will be:

val navigationView = findViewById(R.id.nav_view) as NavigationView
        val headerview = navigationView.getHeaderView(0)
        var imageViewUser = headerview.imgUserProfilNav as ImageView
              headerview.imgUserProfilNav.setImageResource(R.drawable.ic_action_user)
        mUserAuthListener = object : FirebaseAuth.AuthStateListener {
            override fun onAuthStateChanged(p0: FirebaseAuth) {
                var kullanici = p0.currentUser

                if (kullanici != null) {
                    //set image if there is any specific requirement
                }
            }
        }
  • 1
Reply Report