BlitzkriegBlue
BlitzkriegBlue

Reputation: 111

Android ImageView won't load on CustomList with ViewHolder

I have a custom list view which I recently upgraded to use View Holder. Right now the project works fine but the images in the two Image Views don't show on the screen.

enter image description here

This two black icons appear "transparent" but work if I click them.

This is the layout:

  <?xml version="1.0" encoding="UTF-8"?>

    <LinearLayout xmlns:tools="http://schemas.android.com/tools"
        android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">


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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgInfo"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginTop="12dp"
                android:layout_weight="0.04"
                android:visibility="visible"
                app:srcCompat="@drawable/details64" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toEndOf="@+id/imgInfo"
                android:layout_toLeftOf="@+id/imgEdit"
                android:layout_toRightOf="@+id/imgInfo"
                android:layout_weight="0.24"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtChamado"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textAlignment="center"
                    android:textColor="@android:color/background_dark"
                    android:textSize="25sp" />

                <TextView
                    android:id="@+id/txtSolicitante"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAlignment="center"
                    android:textColor="@android:color/background_dark"
                    android:textSize="15sp" />

                <TextView
                    android:id="@+id/txtItemDeCatalogo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAlignment="center"
                    android:textColor="@android:color/background_dark"
                    android:textSize="15sp" />
            </LinearLayout>

            <ImageView
                android:id="@+id/imgEdit"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginTop="12dp"
                android:layout_weight="0.03"
                android:contentDescription=""
                app:srcCompat="@drawable/pencil64" />
        </LinearLayout>


    </RelativeLayout>

</LinearLayout>

This is the code snippet:

 @Override
    public View getView(final int position, View view, final ViewGroup parent) {

        View convertView;
        ViewHolder holder;

        if (view == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.customized_list_view, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            convertView = view;
            holder = (ViewHolder) convertView.getTag();
        }

        //  Object declaration
        final Sette setteData = getItem(position);

        //region Put the Tasks values to the textviews
        // Get me two strings, one with the older value and one with the newest
            String oldChamado = holder.txtChamado.getText().toString();
            String newChamado = setteData.getChamado();
            // Do not repeat the string in the textview
            if (!(oldChamado.equals(newChamado))) {
                holder.txtChamado.setText(newChamado);
            }
     //region Click Listener for the button that leads to Approvals Activity
        if (!aBoolean) {
            holder.imgEdit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    chamadoClicked = setteData.getChamado();
                    solicitanteClicked = setteData.getSolicitante();
                    itemDeCatalogoClicked = setteData.getItemDeCatalogo();
                    id = setteData.getId();

                    Intent intent = new Intent(context.getApplicationContext(), ApprovalsActivity.class);
                    intent.putExtra("Id", id);
                    intent.putExtra("chamadoClicked", chamadoClicked);
                    intent.putExtra("solicitanteClicked", solicitanteClicked);
                    intent.putExtra("itemDeCatalogoClicked", itemDeCatalogoClicked);
                    context.startActivity(intent);
                }
            });
        }
        //endregion
 return convertView;
    }// END METHOD

ViewHolder (which I got from an internet example):

  public class ViewHolder {
    TextView txtChamado;
    TextView txtSolicitante;
    TextView txtItemDeCatalogo;
    ImageView imgInfo, imgEdit;
    Typeface bebasKai;
    Typeface london;

    public ViewHolder(View view){
        bebasKai = Typeface.createFromAsset(context.getAssets(), "fonts/bebaskai.otf");
        london = Typeface.createFromAsset(context.getAssets(), "fonts/london.ttf");
        txtChamado = (TextView) view.findViewById(R.id.txtChamado);
        txtChamado.setTypeface(bebasKai);
        txtSolicitante = (TextView) view.findViewById(R.id.txtSolicitante);
        txtSolicitante.setTypeface(london);
        txtItemDeCatalogo = (TextView) view.findViewById(R.id.txtItemDeCatalogo);
        txtItemDeCatalogo.setTypeface(london);
        imgEdit = (ImageView) view.findViewById(R.id.imgEdit);
        imgInfo = (ImageView) view.findViewById(R.id.imgInfo);
    }
}

I tried clean, rebuild, download the project from BitBucket again, reinstall the app from scratch on my phone, invalidade cache/restart and check the code.

Am I missing something obvious here?

**EDIT:**Thank you SaNtoRiaN, I knew it was something simple that I was missing.

Upvotes: 0

Views: 34

Answers (1)

SaNtoRiaN
SaNtoRiaN

Reputation: 2202

Change app:srcCompat attribute in your ImageView to android:src to view your images properly. To know more about the difference, check this answer.

Upvotes: 1

Related Questions