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 6913553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:14:00+00:00 2026-05-27T09:14:00+00:00

In my application, I have a ListActivity and a custom layout for it. In

  • 0

In my application, I have a ListActivity and a custom layout for it. In the custom layout, I have an ImageView and a TextView.

I want to be able to change the ImageView resource based on some conditional code in my app. However, when I try to image.setImageResource(resource);, I get javaNullPointerException. I have tried placing the code snippet in different places, like after the adapter. Does anyone have any ideas? Thanks in advance.

Also, I did declare the image view before referring to it with ImageView image = (ImageView) findViewById(R.id.image);

EDIT:

In my activity:

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, DlistArray));

    // Here I want to change the image
  ImageView celebIcon = (ImageView) findViewById(R.id.icon);
  celebIcon.setImageResource(R.drawable.phil);

  ListView celebList = getListView();
  registerForContextMenu(getListView());
  celebList.setTextFilterEnabled(true);

In my layout:

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

<ImageView
    android:id="@+id/icon"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginLeft="10dp"
    android:padding="10dp"
    android:src="@drawable/alan" />

<TextView
    android:id="@+id/label"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:layout_gravity="center_vertical"
    android:text="@+id/label"
    android:textColor="#ffffff"
    android:textSize="20dp" />
    </LinearLayout>
  • 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-05-27T09:14:01+00:00Added an answer on May 27, 2026 at 9:14 am

    Use a customized adapter:

    setListAdapter(new ArrayAdapter<String>(getApplicationContext(), R.layout.list_item, R.id.label, yourItems){
                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                        if( convertView == null ){
                            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            convertView = inflater.inflate(R.layout.list_item, null);
                        }
    
                        ImageView image = (ImageView) findViewById(R.id.icon);
                        image.setImageResource(R.drawable.phil);
                        return convertView;
                    }
                });
    

    (You can also just create your own class extending arrayadapter if you want to reuse it)

    To set the text view, just add the code for that in the getView() method, just like the image-setting-code.

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

Sidebar

Related Questions

I see an application have used Log.info = some info where are these logs
In my console application have an abstract Factory class Listener which contains code for
I have an game application I have written for Windows Mobile and I want
I have made an application which calls the phone's contact list but i want
I want my application to look like this. I am able to get names
In my mobile application i am extending ListActivity at one point. i want to
I am developing a soundboard application which extends ListActivity. I have a play button
I have several methods in the ListAC ListActivity that I want to reuse and
I have a database contact application.And i want to display my contact details in
I have a ListActivity containing an object I've defined called a MessageItem. I want

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.