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 7817745

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:20:24+00:00 2026-06-02T06:20:24+00:00

Here I need to pass images into a gallery. In one class I have

  • 0

Here I need to pass images into a gallery.
In one class I have 10 buttons, here when click 1 button I need to pass 1 button related images into the gallery, when click 2 button I need to pass 2 button related images into gallery.
I tried using the below code but here when click 1 button it is working fine means images displayed into gallery, but when I click 2,3 …buttons I got black screen.

Please any one suggest me how to pass different arrays into same activity.

     HomeDemo.class:
   public class HomeDemo extends Activity implements OnTouchListener{
Button home1,home2,home3,home4;
ImageButton back;
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.homedemo);
        home1=(Button)findViewById(R.id.button1);
        home2=(Button)findViewById(R.id.button2);
        home3=(Button)findViewById(R.id.button3);
        home4=(Button)findViewById(R.id.button4);
        home1.setOnTouchListener(this);
        home2.setOnTouchListener(this);
        home3.setOnTouchListener(this);
        home4.setOnTouchListener(this);
 }
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    if(v==home1)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k1", 1);
        startActivity(i);
    }
    if(v==home2)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k2", 2);
        startActivity(i);
    }
    if(v==home3)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k3", 3);
        startActivity(i);
    }
    if(v==home4)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k4", 4);
        startActivity(i);
    }

    return false;
}
}

       Home1 .class
       public class Home1 extends Activity implements
          AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory{
       private TextSwitcher mSwitcher;
   ImageButton home,sound;
Gallery g;
static int nextbtn = 0;
static int prebtn = 0;
ImageAdapter iadapter;
int galpos;
int countk1=0;
int countk2=0;
int countk3=0;
int countk4=0;

public int ht;
public int wt;

public static int motiongal = 3000; 
RelativeLayout l1,l2;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.home1);

    home=(ImageButton)findViewById(R.id.homeimage);
    home.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            Intent i=new Intent(Home1.this,HomeDemo.class);
            startActivity(i);
            return false;
        }
    });
     sound=(ImageButton)findViewById(R.id.soundimage);
      sound.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    });
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    ht = displaymetrics.heightPixels;
    wt = displaymetrics.widthPixels;
 l1=(RelativeLayout)findViewById(R.id.linear);
 l2=(RelativeLayout)findViewById(R.id.linear1);
 l1.setVisibility(View.INVISIBLE);
 l2.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        l1.setVisibility(View.VISIBLE);
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
          public void run() {
            //Do something after 100ms
              l1.setVisibility(View.INVISIBLE);
          }
        }, 1500);
        return false;
    }
});


    mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
    mSwitcher.setFactory(this);
    mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
            android.R.anim.fade_in));
    mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
            android.R.anim.fade_out));
    mSwitcher.startLayoutAnimation();
    try
    {
    g = (Gallery) findViewById(R.id.gallery);
    g.setAdapter(new ImageAdapter(this));
    g.setHorizontalScrollBarEnabled(false);
    Bundle bundle = getIntent().getExtras();
    galpos = bundle.getInt("GALPOS");
     countk1 = getIntent().getIntExtra("k1", 0); 
     countk2 = getIntent().getIntExtra("k2", 0); 
     countk3 = getIntent().getIntExtra("k3", 0); 
     countk4 = getIntent().getIntExtra("k4", 0); 

    g.setSelection(galpos);        
    g.setAnimationDuration(motiongal);


    } catch(Exception e){

  }
    g.setOnItemSelectedListener(this);


    ImageButton nextButton = (ImageButton) findViewById(R.id.nextimage);
    nextButton.setOnClickListener(nextButtonOnClick);

    ImageButton preButton = (ImageButton) findViewById(R.id.preimage);
    preButton.setOnClickListener(preButtonOnClick);



    g.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Toast.makeText(GalleryActivity.this, "" + mTextNames[position] , Toast.LENGTH_SHORT).show();
             if(position==12)
            {
                Intent i=new Intent(Home1.this, HomeDemo.class);
                startActivity(i);
            }
            l1.setVisibility(View.VISIBLE);
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
              public void run() {
                //Do something after 100ms
                  l1.setVisibility(View.INVISIBLE);
              }
            }, 1500);
        }
    });

}



public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    mSwitcher.setText(mTextNames[position]);
    nextbtn = position;



}

public OnClickListener nextButtonOnClick = new OnClickListener(){
    public void onClick(View v) {           

        if(nextbtn < (mTextNames.length-1))
        {     
            try
            {               
            mSwitcher.setText(mTextNames[nextbtn+1]);
            mSwitcher.startLayoutAnimation();               
            mSwitcher.getDrawingTime();
            g.setSelection(nextbtn+1);
            Thread.sleep(300);
            g.scheduleLayoutAnimation();
            g.startLayoutAnimation();
            Thread.sleep(300);
            g.setAnimationDuration(motiongal);  

            }
            catch(Exception e)
            {}

        }else
        {
            try
            {               
            mSwitcher.setText(mTextNames[0]);   
            mSwitcher.startLayoutAnimation();               
            mSwitcher.getDrawingTime();
            g.setSelection(0);
            Thread.sleep(300);
            g.scheduleLayoutAnimation();
            g.startLayoutAnimation();
            Thread.sleep(300);
            g.setAnimationDuration(motiongal);                  
            }
            catch(Exception e)
            {}
        }

      } 
};   

public OnClickListener preButtonOnClick = new OnClickListener(){
    public void onClick(View v) {           

        if(nextbtn > 0)
        {
            try
            {               

            mSwitcher.startLayoutAnimation();               
            mSwitcher.getDrawingTime();
            g.setSelection(nextbtn-1);
            Thread.sleep(300);
            g.scheduleLayoutAnimation();
            g.startLayoutAnimation();
            Thread.sleep(300);
            g.setAnimationDuration(motiongal);

            }
            catch(Exception e)
            {}


        }else
        {
            try
            {               
            mSwitcher.setText(mTextNames[mTextNames.length-1]);
            mSwitcher.startLayoutAnimation();               
            mSwitcher.getDrawingTime();
            g.setSelection(mTextNames.length-1);
            Thread.sleep(300);
            g.scheduleLayoutAnimation();
            g.startLayoutAnimation();
            Thread.sleep(300);
            g.setAnimationDuration(motiongal);                  
            }
            catch(Exception e)
            {}

        }

      } 
};    


public void onNothingSelected(AdapterView<?> parent) {
}

public View makeView() {
    TextView i = new TextView(this);
    i.setTextSize(18);

    i.setGravity(1);
    return i;
}

public class ImageAdapter extends BaseAdapter {
    public ImageAdapter(Context c) {
        mContext = c;
    }

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

    public int getCount() {
        return mPhotos.size();
    }

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(mContext);
       if(countk1==1)
       {
        i.setImageResource(mPhotos.get(position));
       }
       if(countk2==1)
       {
        i.setImageResource(mPhotos1.get(position));
       }
       if(countk2==3)
       {
        i.setImageResource(mPhotos1.get(position));
       }
       if(countk2==4)
       {
        i.setImageResource(mPhotos1.get(position));
       }

        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setLayoutParams(new Gallery.LayoutParams(
               LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        return i;
    }

    private Context mContext;

}


private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
      return e2.getX() > e1.getX();
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
      int kEvent;
      if(isScrollingLeft(e1, e2)){ //Check if scrolling left
        kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
      }
      else{ //Otherwise scrolling right
        kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
      }
      onKeyDown(kEvent, null);
      return true;  
    }


private Integer[] mImageIds = {
         R.drawable.bokstavslottet01,
         R.drawable.bokstavslottet02,
         R.drawable.bokstavslottet03,
         R.drawable.bokstavslottet04,
         R.drawable.bokstavslottet05,
         R.drawable.bokstavslottet06,
         R.drawable.bokstavslottet07,
         R.drawable.bokstavslottet08,
         R.drawable.bokstavslottet09,
         R.drawable.bokstavslottet10,
         R.drawable.bokstavslottet11,
         R.drawable.bokstavslottet12,
         R.drawable.bokstavslottet13
        };

private Integer[] mImageIds1 = {
     R.drawable.i1,
        R.drawable.i2,
        R.drawable.i3,
        R.drawable.i4,
        R.drawable.i5,
        R.drawable.i6,
        R.drawable.i7,
        R.drawable.i8,
        R.drawable.i9,
        R.drawable.i10,
        R.drawable.i11,
        R.drawable.i12,
        R.drawable.i13
    };

private static String[] mTextNames = {
"BOOKSTOVEN1", "BOOKSTOVEN2", "BOOKSTOVEN3", "BOOKSTOVEN4", "BOOKSTOVEN5", "BOOKSTOVEN6", "BOOKSTOVEN7", "BOOKSTOVEN8", "BOOKSTOVEN9", "BOOKSTOVEN10", "BOOKSTOVEN11", "BOOKSTOVEN12", "BOOKSTOVEN13"};



private ArrayList<Integer> mPhotos = new ArrayList<Integer>(Arrays.asList(mImageIds));
private ArrayList<Integer> mPhotos1 = new ArrayList<Integer>(Arrays.asList(mImageIds1));

        }
  • 0 0 Answers
  • 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-02T06:20:25+00:00Added an answer on June 2, 2026 at 6:20 am

    1.First thing i wish to ask with you is, You mentioned here for 1 mPhotos array and for remaining three mPhotos1. If you went right in this code means why you need unnecessary if conditions, you can put else for the first if and supply the mPhotos1 array for remaining (Or other wise you dont need to supply the 2,3,4 values).

    1. Next one is you did a mistake here at if(countk2==1). how it will be possible to compare, because you only pass 2 for the k2 extra.

      if(countk1==1)
         {
          i.setImageResource(mPhotos.get(position));
         }
         if(countk2==1)
         {
          i.setImageResource(mPhotos1.get(position));
         }
         if(countk2==3)
         {
          i.setImageResource(mPhotos1.get(position));
         }
         if(countk2==4)
         {
          i.setImageResource(mPhotos1.get(position));
         }
      
    2. Then, i think you dont need to put Extra values with different names in the following code.

    Here you are receiving k1, k2,k3,k4 values independently. I feel that you dont need to do this.

         countk1 = getIntent().getIntExtra("k1", 0); 
         countk2 = getIntent().getIntExtra("k2", 0); 
         countk3 = getIntent().getIntExtra("k3", 0); 
         countk4 = getIntent().getIntExtra("k4", 0);
    
    
    
    
    
    if(v==home1)
        {
            Intent i=new Intent(HomeDemo.this,Home1.class);
            i.putExtra("k1", 1);
            startActivity(i);
        }
        if(v==home2)
        {
            Intent i=new Intent(HomeDemo.this,Home1.class);
            i.putExtra("k2", 2);
            startActivity(i);
        }
        if(v==home3)
        {
            Intent i=new Intent(HomeDemo.this,Home1.class);
            i.putExtra("k3", 3);
            startActivity(i);
        }
        if(v==home4)
        {
            Intent i=new Intent(HomeDemo.this,Home1.class);
            i.putExtra("k4", 4);
            startActivity(i);
        }
    

    Instead of doing the above, you can putExtra for the intent like the following code.

    if(v==home1)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k", 1);
        startActivity(i);
    }
    if(v==home2)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k", 2);
        startActivity(i);
    }
    if(v==home3)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k", 3);
        startActivity(i);
    }
    if(v==home4)
    {
        Intent i=new Intent(HomeDemo.this,Home1.class);
        i.putExtra("k", 4);
        startActivity(i);
    }
    

    And then you can receive like the following code,

         count = getIntent().getIntExtra("k", 0); 
    

    And in the Adapter you can follow this,

       if(count==1)
       {
        i.setImageResource(mPhotos.get(position));
       }
       else if(count==2)
       {
        i.setImageResource(mPhotos1.get(position));
       }
       else if(count==3)
       {
        i.setImageResource(mPhotos2.get(position));
       }
       if(count==4)
       {
        i.setImageResource(mPhotos3.get(position));
       }
    

    I hope that you have understand the above explanation.

    And here are some useful solutions.

    For receiving the Extras
    You can do like the following also,

    getIntent.getIntExtrta("k",0) without using Bundle.

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

Sidebar

Related Questions

hi i am doing one application here i need to disply 6 images in
i have day, month, year, value columns in one table, here i need to
I have a variable that contains JSON I need to pass into a template.
Here is my project, I have a GUI that loads images and I need
I need to pass an url from asp.net load_page to flowplayer javascript function here:
I tried this JavaScript but it doesn't work - here I need to change
I really need help here. I'm desperate at this point. I have NSOperation that
here it goes; echo <a href='#' class='thumb'><img class='thumb-img' value = .$row->aid. onclick='getVote(.$row->aid., \.$row->atitle.\)' src='images/roadies/th.$row->aid..jpg'
Here's my current workflow: Load POJOs from the database. Pass them into Velocity, rendering
I have been having a look to some post here related to the post

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.