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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:30:51+00:00 2026-06-08T11:30:51+00:00

I have been breaking my head trying to get this working but I can’t

  • 0

I have been breaking my head trying to get this working but I can’t to save my life, I was hoping one of you guys knew how to do it. Basically, I have a list of nature pictures that are loading in a lazy ListView, but my problem is that I can only make the row clickable. I need to make the the individual images clickable. Everything else works like a charm, I really appreciate the help.

Activity:

public class AmainActivityNature extends Activity {

    ListView list;
    LazyAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        list=(ListView)findViewById(R.id.list);
        adapter=new LazyAdapter(this, mStrings, mphotos);
        list.setAdapter(adapter);

        Button bLeft = (Button) findViewById(R.id.buttonLeft);
        bLeft.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent mainIntentOne = new Intent(AmainActivityNature.this, AmainActivityNature.class);
                AmainActivityNature.this.startActivity(mainIntentOne);

                /* Finish splash activity so user cant go back to it. */
                AmainActivityNature.this.finish();

                /* Apply our splash exit (fade out) and main
                   entry (fade in) animation transitions. */
                overridePendingTransition(R.anim.animation_enterl, R.anim.animation_leaver);


            }   
            });
        Button bRight = (Button) findViewById(R.id.buttonRight);
        bRight.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent("com.testing.image.AMAINACTIVITYNATURE"));
                finish();
            }
            });

list.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                 switch (arg2)
                 {
                    case 0:
                     Intent newActivity0 = new Intent(AmainActivityNature.this,NatureTwoOne.class);     
                     startActivity(newActivity0);
                    break;
                    case 1:
                     Intent newActivity1 = new Intent(AmainActivityNature.this,NatureTwoTwo.class);     
                     startActivity(newActivity1);
                    break;
                    case 2:
                     Intent newActivity2 = new Intent(AmainActivityNature.this,NatureTwoThree.class);     
                     startActivity(newActivity2);
                    break;
                    case 3:
                     Intent newActivity3 = new Intent(AmainActivityNature.this,NatureTwoFour.class);     
                     startActivity(newActivity3);
                    break;
                    case 4:
                         Intent newActivity4 = new Intent(AmainActivityNature.this,NatureTwoFive.class);     
                         startActivity(newActivity4);
                        break;
                        case 5:
                         Intent newActivity5 = new Intent(AmainActivityNature.this,NatureTwoSix.class);     
                         startActivity(newActivity5);
                        break;
                        case 6:
                         Intent newActivity6 = new Intent(AmainActivityNature.this,NatureTwoSeven.class);     
                         startActivity(newActivity6);
                        break;
                        case 7:
                         Intent newActivity7 = new Intent(AmainActivityNature.this,NatureTwoEight.class);     
                         startActivity(newActivity7);
                        break;
                        case 8:
                             Intent newActivity8 = new Intent(AmainActivityNature.this,NatureTwoNine.class);     
                             startActivity(newActivity8);
                            break;
                            case 9:
                             Intent newActivity9 = new Intent(AmainActivityNature.this,NatureTwoTen.class);     
                             startActivity(newActivity9);
                            break;
                            case 10:
                             Intent newActivity10 = new Intent(AmainActivityNature.this,NatureTwoEleven.class);     
                             startActivity(newActivity10);
                            break;
                            case 11:
                             Intent newActivity11 = new Intent(AmainActivityNature.this,NatureTwoTwoelve.class);     
                             startActivity(newActivity11);
                            break;
                            case 12:
                                 Intent newActivity12 = new Intent(AmainActivityNature.this,NatureTwoThirteen.class);     
                                 startActivity(newActivity12);
                                break;
                                case 13:
                                 Intent newActivity13 = new Intent(AmainActivityNature.this,NatureTwoFourteen.class);     
                                 startActivity(newActivity13);
                                break;
                                case 14:
                                 Intent newActivity14 = new Intent(AmainActivityNature.this,NatureTwoFifteen.class);     
                                 startActivity(newActivity14);
                                break;
                                case 15:
                                 Intent newActivity15 = new Intent(AmainActivityNature.this,NatureTwoSixteen.class);     
                                 startActivity(newActivity15);
                                break;
                                case 16:
                                     Intent newActivity16 = new Intent(AmainActivityNature.this,NatureTwoSeventeen.class);     
                                     startActivity(newActivity16);
                                    break;
                                    case 17:
                                     Intent newActivity17 = new Intent(AmainActivityNature.this,NatureTwoEighteen.class);     
                                     startActivity(newActivity17);
                                    break;
                                    case 18:
                                     Intent newActivity18 = new Intent(AmainActivityNature.this,NatureTwoNineteen.class);     
                                     startActivity(newActivity18);
                                    break;
                                    case 19:
                                         Intent newActivity19 = new Intent(AmainActivityNature.this,NatureTwoTwoenty.class);     
                                         startActivity(newActivity19);
                                        break;
                                        case 20:
                                         Intent newActivity20 = new Intent(AmainActivityNature.this,NatureTwoTwoentyone.class);     
                                         startActivity(newActivity20);
                                        break;
                                        case 21:
                                         Intent newActivity21 = new Intent(AmainActivityNature.this,NatureTwoTwoentytwo.class);     
                                         startActivity(newActivity21);
                                        break;
                                        case 22:
                                         Intent newActivity22 = new Intent(AmainActivityNature.this,NatureTwoTwoentythree.class);     
                                         startActivity(newActivity22);
                                        break;
                                        case 23:
                                             Intent newActivity23 = new Intent(AmainActivityNature.this,NatureTwoTwoentyfour.class);     
                                             startActivity(newActivity23);
                                            break;
                                            case 24:
                                             Intent newActivity24 = new Intent(AmainActivityNature.this,NatureTwoTwoentyfive.class);     
                                             startActivity(newActivity24);
                                            break;
                    default:
                      // Nothing do!
                  }
            }
        });

        Button b=(Button)findViewById(R.id.button1);
        b.setOnClickListener(listener);
    }

    @Override
    public void onDestroy()
    {
        list.setAdapter(null);
        super.onDestroy();
    }

    public OnClickListener listener=new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            adapter.imageLoader.clearCache();
            adapter.notifyDataSetChanged();
        }
    };

    private String[] mphotos={
            "http:testingsite.com/naturemain/2.jpg",
            "http:testingsite.com/naturemain/4.jpg",
            "http:testingsite.com/naturemain/6.jpg",
            "http:testingsite.com/naturemain/8.jpg",
            "http:testingsite.com/naturemain/10.jpg",
            "http:testingsite.com/naturemain/12.jpg",
            "http:testingsite.com/naturemain/14.jpg",
            "http:testingsite.com/naturemain/16.jpg",
            "http:testingsite.com/naturemain/18.jpg",
            "http:testingsite.com/naturemain/20.jpg",
            "http:testingsite.com/naturemain/22.jpg",
            "http:testingsite.com/naturemain/24.jpg",
            "http:testingsite.com/naturemain/26.jpg",
            "http:testingsite.com/naturemain/28.jpg",
            "http:testingsite.com/naturemain/30.jpg",
            "http:testingsite.com/naturemain/32.jpg",
            "http:testingsite.com/naturemain/34.jpg",
            "http:testingsite.com/naturemain/36.jpg",
            "http:testingsite.com/naturemain/38.jpg",
            "http:testingsite.com/naturemain/40.jpg",
            "http:testingsite.com/naturemain/42.jpg",
            "http:testingsite.com/naturemain/44.jpg",
            "http:testingsite.com/naturemain/46.jpg",
            "http:testingsite.com/naturemain/48.jpg",
            "http:testingsite.com/naturemain/50.jpg"
    };

    private String[] mStrings={
            "http:testingsite.com/naturemain/1.jpg",
            "http:testingsite.com/naturemain/3.jpg",
            "http:testingsite.com/naturemain/5.jpg",
            "http:testingsite.com/naturemain/7.jpg",
            "http:testingsite.com/naturemain/9.jpg",
            "http:testingsite.com/naturemain/11.jpg",
            "http:testingsite.com/naturemain/13.jpg",
            "http:testingsite.com/naturemain/15.jpg",
            "http:testingsite.com/naturemain/17.jpg",
            "http:testingsite.com/naturemain/19.jpg",
            "http:testingsite.com/naturemain/21.jpg",
            "http:testingsite.com/naturemain/23.jpg",
            "http:testingsite.com/naturemain/25.jpg",
            "http:testingsite.com/naturemain/27.jpg",
            "http:testingsite.com/naturemain/29.jpg",
            "http:testingsite.com/naturemain/31.jpg",
            "http:testingsite.com/naturemain/33.jpg",
            "http:testingsite.com/naturemain/35.jpg",
            "http:testingsite.com/naturemain/37.jpg",
            "http:testingsite.com/naturemain/39.jpg",
            "http:testingsite.com/naturemain/41.jpg",
            "http:testingsite.com/naturemain/43.jpg",
            "http:testingsite.com/naturemain/45.jpg",
            "http:testingsite.com/naturemain/47.jpg",
            "http:testingsite.com/naturemain/49.jpg"
    };

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);
        MenuInflater menuinflater = getMenuInflater();
        menuinflater.inflate(R.menu.main_menu, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
                switch(item.getItemId()){
                case R.id.inflate:

                    startActivity(new Intent("com.testing.image.ABOUTUS"));
                    return true;
                }

                return false;
            }
}

Row XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="150dip"
        android:layout_height="120dip"
        android:scaleType="centerCrop"
        android:src="@drawable/backgroundimage" />

    <TextView
        android:layout_width="20dip"
        android:layout_height="1dip" />

    <TextView
        android:layout_width="1dip"
        android:layout_height="150dip" />

    <ImageView
        android:id="@+id/photo"
        android:layout_width="150dip"
        android:layout_height="120dip"
        android:scaleType="centerCrop"
        android:src="@drawable/stub" />

    <TextView
        android:id="@+id/text"
        android:layout_width="1dip"
        android:layout_height="1dip" />

</LinearLayout>

Main XML:

<ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1"
        />

Sub-Activity:

public class NatureTwoOne extends Activity {

    ImageView image;
    private class BackgroundTask extends AsyncTask<String, Void, Bitmap> {
        protected Bitmap doInBackground(String...url) {
            //--- download an image ---
            Bitmap bitmap = DownloadImage(url[0]);
            return bitmap;
        }
        protected void onPostExecute(Bitmap bitmap) {
            ImageView image = (ImageView) findViewById(R.id.imageView1);
            bitmaptwo=bitmap;
            image.setImageBitmap(bitmap);
        }
    }

    private InputStream OpenHttpConnection(String urlString) throws IOException {
        InputStream in = null;
        int response= -1;
        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();
        if (!(conn instanceof HttpURLConnection ))
            throw new IOException("Not an HTTP connection");
        try {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            response = httpConn.getResponseCode();
            if (response == HttpURLConnection.HTTP_OK){
                in = httpConn.getInputStream();
            }
        }
        catch (Exception ex) {
            throw new IOException("Error connecting");
        }
        return in;
    }

    private Bitmap DownloadImage(String URL)
    {
        Bitmap bitmap = null;
        InputStream in = null;
        try {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in);
            in.close();
        }
        catch (IOException e1){
            Toast.makeText(this,e1.getLocalizedMessage(),
                    Toast.LENGTH_LONG).show();

            e1.printStackTrace();
        }
        return bitmap;
    }
    public static Bitmap bitmaptwo;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.wallpaper);
        new BackgroundTask().execute("http:testingsite.com/natureone/1.jpg");
        Button setWallpaper = (Button) findViewById(R.id.button3);
        setWallpaper.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                WallpaperManager wManager;
                Toast noSong = Toast.makeText(NatureTwoOne.this, "Background Set", Toast.LENGTH_SHORT);
                noSong.show();
                try {
                    // bitmap = BitmapFactory.decodeFile(null);
                    wManager = WallpaperManager.getInstance(getApplicationContext());
                    wManager.setBitmap(bitmaptwo);

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        Button bLeft = (Button) findViewById(R.id.buttonLeft);
        bLeft.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent mainIntentOne = new Intent(NatureTwoOne.this, NatureTwoFifty.class);
                NatureOneOne.this.startActivity(mainIntentOne);
                if(bitmaptwo != null){
                    bitmaptwo.recycle();
                }                              
                /* Finish splash activity so user cant go back to it. */
                NatureOneOne.this.finish();

                /* Apply our splash exit (fade out) and main
                   entry (fade in) animation transitions. */
                overridePendingTransition(R.anim.animation_enterl, R.anim.animation_leaver);
            }   
        });
        Button bRight = (Button) findViewById(R.id.buttonRight);
        bRight.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent("com.testing.image.NATURETWOTWO"));
                if(bitmaptwo != null){
                    bitmaptwo.recycle();
                }

                finish();
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if(bitmaptwo != null){
                bitmaptwo.recycle();
            }
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);
        MenuInflater menuinflater = getMenuInflater();
        menuinflater.inflate(R.menu.main_menu, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch(item.getItemId()){
        case R.id.inflate:
            startActivity(new Intent("com.testing.image.ABOUTUS"));
            return true;
        }
        return false;
    }
}

Adapter:

public class LazyAdapter extends BaseAdapter {

    private Activity activity;
    private String[] data;
    private String[] dataone;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;

    public LazyAdapter(Activity a, String[] d, String[] mphotos) {
        activity = a;
        data=d;
        dataone = mphotos;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.length;
    }

    public int getCountOne() {
        return dataone.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item, null);

        TextView text=(TextView)vi.findViewById(R.id.text);;
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        ImageView photos=(ImageView)vi.findViewById(R.id.photo);
        text.setText("item "+position);
        imageLoader.DisplayImage(data[position], image);
        imageLoader.DisplayImage(dataone[position], photos);
        return vi;
    }
}
  • 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-08T11:30:52+00:00Added an answer on June 8, 2026 at 11:30 am

    You have 50 different specific sub-Activities for the job of one generic… let’s address this and we’ll give both images in each row a click listener.

    To start you can define these String arrays of JPGs as such:

    public String[] mPhotos = new String[25];
    public String[] mStrings = new String[25];
    
    public void onCreate(Bundle savedInstances) {
        ...
    
        String prefix = "http:testingsite.com/natureone/";
        String suffix = ".jpg";
        for(int index = 1; index <= 25; index++) {
            mPhotos[index - 1] = prefix + (index * 2) + suffix; // evens: 2 - 50
            mStrings[index - 1] = prefix + (index * 2 - 1) + suffix; // odds: 1 - 49
        }
    }
    

    If you ever add more images or change things around, you have less maintenance now.

    Next create the appropriate Intent, let’s create a generic OnClickListener as a class variable in LazyAdapter:

    OnClickListener mListener = new OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent(activity, ViewActivity.class);
            intent.putExtra("Image Index", (Integer) view.getTag());
            activity.startActivity(intent);
        }
    };
    

    and change getView() in your LazyAdapter:

    ...
    text.setText("item "+position);
    
    imageLoader.DisplayImage(data[position], image);
    image.setTag(position + 1);
    image.setOnClickListener(mListener);
    
    imageLoader.DisplayImage(dataone[position], photos);
    photos.setTag(position + 2);
    photos.setOnClickListener(mListener);
    
    return vi;
    

    Now Change these in one of your sub-Activities and call in ViewActivity (don’t forget to update your manifest!):

    new BackgroundTask().execute("http:testingsite.com/natureone/1.jpg");
    

    becomes:

    mIndex = getIntent().getIntExtra("Image Index", 1);
    new BackgroundTask().execute("http:testingsite.com/natureone/" + mIndex + ".jpg");
    

    bLeft can become:

    bLeft.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mIndex--;
            if(mIndex < 1)
                mIndex = 50;
            new BackgroundTask().execute("http:testingsite.com/natureone/" + mIndex + ".jpg");
        }
    });
    

    and bRight vica versa. This won’t be perfect but it should get you going in the right direction. Hope that helps!

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

Sidebar

Related Questions

Alright, I have been breaking my head over this one for more than a
I've been breaking my head on this easy validation and I can't get it
I have been coding for a while now but just can't seem to get
I have been breaking my head over this. I have a ndk c++ app
I have been breaking my head over this hope it's possible declare @locationType varchar(50);
I have been breaking my head for 3 hours now and I can't figure
This is breaking my head, I have 2 functions 1) to get an ID
I have been breaking my head over this for quite some time now.I am
Have been working on this question for a couple hours and have come close
I have been working with SQL Server as a Developer a while. One thing

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.