Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:45:12+00:00 2026-06-13T00:45:12+00:00

Hi I have a Custom ListView with one ImageView and TextView . Here is

  • 0

Hi I have a Custom ListView with one ImageView and TextView. Here is the class which object should be shown

package mk.mk.mk;

public class Artist {

private String artistName;
private String artistImage;
private String artistNameLatin;
 public Artist() {
    // TODO Auto-generated constructor stub
}
 public String getArtistImage() {
    return artistImage;
}
  public String getArtistName() {
    return artistName;
}
 public String getArtistNameLatin() {
    return artistNameLatin;
}
public void setArtistNameLatin(String artistNameLatin) {
this.artistNameLatin = artistNameLatin;
}



 public void setArtistImage(String artistImage) {
    this.artistImage = artistImage;
}
  public void setArtistName(String artistName) {
    this.artistName = artistName;
}
public Artist (String _artistName,String _artistImage,String _artistNameLatin)
{
    artistName=_artistName;
    artistImage=_artistImage;
    artistNameLatin=_artistNameLatin;

}

While the code for the custom adapter is this one

package mk.mk.mk;



import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.style.RelativeSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ArtistAdapter extends ArrayAdapter<Artist>{

int resource;
private static final String ASSETS_DIR="images/";

public ArtistAdapter(Context _context,int _resource,List<Artist> objects)
{
    super(_context,_resource,objects);
    resource=_resource;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    RelativeLayout artistLayoutView;
    Artist a=getItem(position);
    String artistName=a.getArtistName();

    if(convertView==null)
    {
        artistLayoutView=new RelativeLayout(getContext());
        String inflater=Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater vi=(LayoutInflater)getContext().getSystemService(inflater);
        vi.inflate(resource, artistLayoutView,true);
    }
    else
    {
        artistLayoutView=(RelativeLayout)convertView;
    }


    TextView artistTxt=(TextView)artistLayoutView.findViewById(R.id.artistName);
    ImageView resourceIdView=(ImageView)artistLayoutView.findViewById(R.id.artist_icon);
    artistTxt.setText(artistName);
    String imgFilePath=ASSETS_DIR+a.getArtistImage();

    try
    {
        Drawable d=Drawable.createFromStream(getContext().getAssets().open(imgFilePath), null);
        resourceIdView.setImageDrawable(d);
    }
    catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return artistLayoutView;
}

}

The code where the items should be populated is this one

package mk.mk.mk;

import java.util.ArrayList;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.ListView;

public class ArtistList extends Activity{

ArrayList <String> artistNameList=new ArrayList<String>();
ArrayList <String> artistNameLatinList=new ArrayList<String>();
ArrayList <String> artistImageUrlList=new ArrayList<String>();
ArrayList<Artist> artistList=new ArrayList<Artist>();

private ArtistAdapter aa;
private ListView listViewArtists;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.artist_list);
    Resources r=getResources();

    String [] artistNameListArray=r.getStringArray(R.array.artists);
    String [] artistImageUrlListArray=r.getStringArray(R.array.artists_url);
    String [] artistLatinList=r.getStringArray(R.array.artistsLatin);


    for(int j=0;j<artistNameListArray.length;j++)
    {
        artistList.add(new Artist(artistNameListArray[j],artistImageUrlListArray[j],artistLatinList[j]));
    }

    listViewArtists=(ListView)findViewById(R.id.listArtists);
    aa=new ArtistAdapter(ArtistList.this, R.layout.artist_listitem, artistList);
    listViewArtists.setAdapter(aa);

}

}

The layout for the listView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/listArtists"
    android:layout_width="wrap_content"
    android:layout_height="370dp"
    android:layout_marginTop="50dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_centerVertical="true">

</ListView>

</RelativeLayout>

And the layout for the list item

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
    android:id="@+id/artist_icon"
    android:layout_width="40dp"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_gravity="left" />

<TextView
    android:id="@+id/artistName"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_toRightOf="@+id/artist_icon"
    android:fadingEdge="vertical"
    android:padding="10dp"
    android:scrollbars="vertical"
    android:textSize="25sp" />



</RelativeLayout>

However when I run my application the image isn’t shown and I didn’t get any error. The images are in folder images in the application folder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:45:13+00:00Added an answer on June 13, 2026 at 12:45 am

    The code above is it OK, the problem was that images folder wasn’t in assets folder. Now it is working fine for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one custom ListView which contains one ImageView and one TextView, and I
I have a Custom ListView which has an ImageView and a TextView. and i
I have a custom ArrayAdapter populating a ListView . Here it is: public class
I have a custom ListView which contains one TextView (Of numbers) and one EditText
I have a custom listview in which one textview and one checked box is
I have a custom ListView in which there are 2 buttons and a textview
I have a custom listview which display an image, textview and radio button. I
I have one custom ListView called AreasListView which I've included in the XML file.
I have a custom listview row whose XML has one ImageView and three TextViews
I have a custom listview which changes size when one of the rows is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.