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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:36:05+00:00 2026-06-04T01:36:05+00:00

So i’ve searched and searched and I’ve found nothing like I’m looking. I have

  • 0

So i’ve searched and searched and I’ve found nothing like I’m looking. I have several ListActivities and I can click one and go to the next list and next list etc… What I want is when i click on the appropriate list item i want it to display an image from the res folder. I have been stuck on this all afternoon and nothing is working that i can find. Any help would be great. Example When CoverSheet is selected it retrieves cover_sheet.png.
Thanks James

The entry point of the application: Menu.java

public class Menu extends ListActivity 
{ 
    public static final String EXTRA_PICTURE = "extra.picture.toshow"; 

    String classes[] = { "CoverSheet",// "TreatmentProtocols", "EMSProcedures",
           // "DrugList", "EMSPolicies", "EMSTriageAndDestinationPlan",  
           // "Appendices"
            }; 
    //in this array you store the drawable resource ids to show.  
    //you can change it to hold urls or other identifiers. 
    int images[] = { R.drawable.cover_sheet, }; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setListAdapter(new ArrayAdapter<String>(Menu.this,  
                android.R.layout.simple_list_item_1, classes)); 
    } 

    protected void onCreate1(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.imageview); 
        final int imgResource = getIntent().getIntExtra(Menu.EXTRA_PICTURE, 0);
        final ImageView img = (ImageView)findViewById(R.id.img); 
        img.setImageResource(imgResource); }

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) 
    { 
        super.onListItemClick(l, v, position, id); 
        String Menu = classes[position]; 
        try 
        { 
            Class firstClass = Class.forName("protocols.NashCounty." + Menu); 
            Intent firstIntent = new Intent(Menu.this, firstClass); 
            firstIntent.putExtra(EXTRA_PICTURE, images[position]); 
            startActivity(firstIntent); 
        } 
        catch (ClassNotFoundException e) 
        { 
            Log.e("SAMPLE", "ClassNotFoundException ", e); 
        } 
        catch (Exception e) 
        { 
            Log.e("SAMPLE", "Exception ", e); 
        } 
    } 
} 

This is my Class i’ve created

public class CoverSheet extends ListActivity
{
    public static final String EXTRA_PICTURE = "extra.picture.toshow";
    String classes[] = { "CoverSheet", };
    // in this array you store the drawable resource ids to show.
    // you can change it to hold urls or other identifiers.
    int images[] = { R.drawable.cover_sheet };

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imageview);
        final int imgResource = getIntent().getIntExtra(
                CoverSheet.EXTRA_PICTURE, 0);
        final ImageView img = (ImageView) findViewById(R.id.img);
        img.setImageResource(imgResource);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
        super.onListItemClick(l, v, position, id);
        String coversheet = classes[position];
        try
        {
            Class firstClass = Class.forName("protocols.NashCounty."+classes);
            Intent firstIntent = new Intent(CoverSheet.this, firstClass);
            firstIntent.putExtra(EXTRA_PICTURE, images[position]);
            startActivity(firstIntent);
        }
        catch (ClassNotFoundException e)
        {
            Log.e("SAMPLE", "ClassNotFoundException ", e);
        }
        catch (Exception e)
        {
            Log.e("SAMPLE", "Exception ", e);
        }
    }
}

Below is my xml layout l named imageview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <ImageView android:id="@+id/img"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/cover_sheet" />
</LinearLayout>

and below is my minifest

<activity android:name=".activity.CoverSheet"  
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /> 
</application>
</manifest>

i was misunderstanding what you were saying earlier and i apologize for that i think im starting to undestand it…i think.

below is my logcat error when trying to run the code:

05-18 17:15:26.221: E/AndroidRuntime(618): FATAL EXCEPTION: main
05-18 17:15:26.221: E/AndroidRuntime(618): java.lang.ArrayIndexOutOfBoundsException: length=1; index=3
05-18 17:15:26.221: E/AndroidRuntime(618): at protocols.NashCounty.Menu.onListItemClick(Menu.java:40)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.widget.AbsListView$1.run(AbsListView.java:3168)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.os.Handler.handleCallback(Handler.java:605)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.os.Handler.dispatchMessage(Handler.java:92)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.os.Looper.loop(Looper.java:137)
05-18 17:15:26.221: E/AndroidRuntime(618): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-18 17:15:26.221: E/AndroidRuntime(618): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 17:15:26.221: E/AndroidRuntime(618): at java.lang.reflect.Method.invoke(Method.java:511)
05-18 17:15:26.221: E/AndroidRuntime(618): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-18 17:15:26.221: E/AndroidRuntime(618): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-18 17:15:26.221: E/AndroidRuntime(618): at dalvik.system.NativeStart.main(Native Method)

  • 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-04T01:36:07+00:00Added an answer on June 4, 2026 at 1:36 am

    I assume you are showing images in the activities whose names are listed inside the classes variable.

    Make sure all the classes listed there are also included in the androidManifest.xml with a proper <activity />tag and with the correct package declaration!

    Your use of casing the variables and package names is misleading, but I think your application package is protocols.NashCountry, so inside the manifest there should be a line similar to this:

    <activity android:name=".activity.CoverSheet" android:label="@string/app_name" />
    

    for each activity class you want to call.

    You should also try to change the

    e.printStackTrace();
    

    into

    Log.e("SAMPLE", "ClassNotFoundException ", e);
    

    Edit: To make your subsequent activities to be displayed in full screen, you need to set android:theme attribute in your manifest:

    <activity android:name=".activity.CoverSheet" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    <activity android:name=".activity.TreatmentProtocols" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    

    the code below shows how to deal with Intent extras:

    public class Menu extends ListActivity
    {
        public static final String EXTRA_PICTURE = "extra.picture.toshow";
        String classes[] = { "CoverSheet", "TreatmentProtocols", "EMSProcedures", 
                "DrugList", "EMSPolicies", "EMSTriageAndDestinationPlan", 
                "Appendices" };
        //in this array you store the drawable resource ids to show. 
        //you can change it to hold urls or other identifiers.
        int images[] = { R.drawable.coversheet, R.drawable.img2, R.drawable.img3, 
            R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7};
    
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setListAdapter(new ArrayAdapter<String>(Menu.this, 
                    android.R.layout.simple_list_item_1, classes));
        }
    
        @Override
        protected void onListItemClick(ListView l, View v, int position, long id)
        {
            super.onListItemClick(l, v, position, id);
            String Menu = classes[position];
            try
            {
                Class firstClass = Class.forName("protocols.NashCounty." + Menu);
                Intent firstIntent = new Intent(Menu.this, firstClass);
                firstIntent.putExtra(EXTRA_PICTURE, images[position]);
                startActivity(firstIntent);
            }
            catch (ClassNotFoundException e)
            {
                Log.e("SAMPLE", "ClassNotFoundException ", e);
            }
            catch (Exception e)
            {
                Log.e("SAMPLE", "Exception ", e);
            }
        }
    }
    

    And finally, the onCreate methods in your classes should display the proper image based on the extra provided to them:

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.full_img);
        final int imgResource = getIntent().getIntExtra(Menu.EXTRA_PICTURE, 0);
        final ImageView img = (ImageView)findViewById(R.id.img);
        img.setImageResource(imgResource);
    }
    

    Please note, that if you just need to display different images based on list item clicks, you don’t need separate activities, and you don’t have to access them by name: you should use a single activity, and pass the id of the image to it as an extra parameter when starting the intent.

    Edit: Your CoverSheet activity class should look like this:

    public class CoverSheet extends Activity
    {
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.imageview);
            final int imgResource = getIntent().getIntExtra(Menu.EXTRA_PICTURE, 0);
            final ImageView img = (ImageView)findViewById(R.id.img);
            img.setImageResource(imgResource);
        }
    }
    

    It is very simple, no need to extend ListActivity, since you don’t want to deal with any list there, you just want to display a picture.

    Other variables are also useless for this scenario!

    Edit 2: Your onListItemClick method should get simpler too! There is no need for dynamically retrieve classes, so you can completely remove the classes array variable from your Menu activity as well.

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
        super.onListItemClick(l, v, position, id);
        try
        {
            Intent firstIntent = new Intent(Menu.this, CoverSheet.class);
            firstIntent.putExtra(EXTRA_PICTURE, images[position]);
            startActivity(firstIntent);
        }
        catch (Exception e)
        {
            Log.e("SAMPLE", "Exception ", e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.