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

  • Home
  • SEARCH
  • 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 8168779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:38:29+00:00 2026-06-06T20:38:29+00:00

I am trying to insert an image in ListView and when I click on

  • 0

I am trying to insert an image in ListView and when I click on it to display the image in a new image view (Bigger View).

I don’t have an Android phone to execute my application.

This is my ImageViewer class.

public class ImageViewer extends ListActivity {

   Uri uri;
   Cursor c;
   ListView l;
   ArrayList<String> al1 = new ArrayList<String>();
   ArrayList<String> al2 = new ArrayList<String>();
   int data, dname;
   String dt, disnam, imgid;
   int id;
   String type;


   @Override
   protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);

      uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
      String project[] = {MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA,
            MediaStore.Images.Media._ID};
      c = getContentResolver().query(uri, project, null, null, null);
      data = c.getColumnIndex(MediaStore.Images.Media.DATA);
      dname = c.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME);
      id = c.getColumnIndex(MediaStore.Images.Media._ID);

      if (c.moveToFirst()) {
         do {
            dt = c.getString(data);
            disnam = c.getString(dname);
            imgid = c.getString(id);
            al1.add(dt);
            al2.add(disnam);
         } while (c.moveToNext());
      }
      l = getListView();
      l.setAdapter(new MyAdapter());
      l.setOnItemClickListener(new OnItemClickListener() {

         @Override
         public void onItemClick(
               AdapterView<?> arg0,
               View arg1, int arg2, long arg3
         ) {

            String filename = al1.get(arg2);
            Intent intent = new Intent(ImageViewer.this, Viewer.class);
            intent.putExtra("image2view", filename);
            intent.putExtra("type", type);
            intent.putExtra("id", id);
            startActivity(intent);
         }
      });
   }


   public class MyAdapter extends BaseAdapter {

      @Override
      public int getCount() {
         // TODO Auto-generated method stub
         return 0;
      }

      @Override
      public Object getItem(int arg0) {
         // TODO Auto-generated method stub
         return null;
      }

      @Override
      public long getItemId(int arg0) {
         // TODO Auto-generated method stub
         return 0;
      }

      @Override
      public View getView(int pos, View convertview, ViewGroup vg) {
         // TODO Auto-generated method stub


         View row = convertview;
         if (row == null) {
            LayoutInflater inf = getLayoutInflater();
            row = inf.inflate(R.layout.image, vg, false);
         }

         TextView filename = (TextView) row.findViewById(R.id.ImageName);
         filename.setText(al2.get(pos) + "\n");

         ImageView thumbs = (ImageView) row.findViewById(R.id.Thumb);
         thumbs.setImageResource(id);
         thumbs.setScaleType(ImageView.ScaleType.CENTER_CROP);
         thumbs.setPadding(8, 8, 28, 8);

         return row;
      }
   }
}

This is my Viewer class, which has to display the selected image in full screen.

public class Viewer extends Activity{
    
    ImageView iv;
    TextView tv;
    public void onCreate(Bundle b1){
        super.onCreate(b1);
        
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        
        setContentView(R.layout.imageview);
                System.gc();
                
        Bundle b2=getIntent().getExtras();
        //String file=b2.getString("image2view");
        int id=b2.getInt("id");
        
        iv=(ImageView)findViewById(R.id.imageView101);
        iv.setImageResource(id);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                R.layout.help_title);
        ImageView iv = (ImageView) findViewById(R.id.header);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                new Intent();
                setResult(RESULT_OK);
                finish();
            }
        });
    }
}

The xml file used for ImageViewer class is image.xml.

<RelativeLayout 
    android:id="@+id/RelativeLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:background="@drawable/mainbkgnd" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:id="@+id/Thumb"
        android:layout_width="50dp"
        android:layout_height="70dp"
        android:src="@drawable/ic_launcher"/>

    <TextView 
        android:layout_width="wrap_content" 
        android:layout_toRightOf="@+id/Thumb" 
        android:layout_height="wrap_content" 
        android:id="@+id/ImageName"
        android:text="Image Name"
        android:textColor="#000000">
    </TextView>
    
</RelativeLayout>

The xml code for the Viewer class is imageview.xml.

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

    <TextView
    android:id="@+id/itextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:visibility="gone" />

    <ImageView
        android:id="@+id/imageView101"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.62"
        android:src="@drawable/ic_launcher" />
    
</LinearLayout>

I searched but I couldn’t find suitable code.

  • 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-06T20:38:31+00:00Added an answer on June 6, 2026 at 8:38 pm

    I don’t believe that this id:

    id=c.getColumnIndex(MediaStore.Images.Media._ID);
    

    Is the appropriate resource id for:

    iv.setImageResource(id);
    

    You should be able to do this in Viewer’s onCreate() instead:

    String filename = b2.getString("filename");
    if(filename != null)
        iv.setImageUri(Uri.fromFile(new File(filename)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code I have. I'm trying to insert a image to show
I am trying to insert a new image into my Magento invoice or packing
I have a JTable , and I am trying to insert an image behind
I'm trying to insert a signature image into emails sent from my application. I
i'm trying to insert an image in a div container using css and html,
I'm trying to insert a new meta tag within the Head, I'm using a
When im trying to insert image with path like this: /wombat/htdocs/web/icon.png after insert its
I am trying to insert an image into a table cell based off a
I'm trying to get the thumbnails from Youtube and insert the corresponding image into
I'm trying to insert an image into the database. CREATE TABLE ImageTable ( Id

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.