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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:08:42+00:00 2026-06-02T10:08:42+00:00

Hello I have a gallery with 2 images in it. I want each time

  • 0

Hello I have a gallery with 2 images in it. I want each time i change the image a textview in my layout to change its name. In my code it happens only the first time and remains that way.

public class BrowseActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_activity_layout);

    Gallery gallery = (Gallery) findViewById(R.id.browseActivityGallery);
    gallery.setAdapter(new ImageAdapter(this)); 
    gallery.setSpacing(0); 
}
public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;

    private Integer[] mImageIds = {

            R.drawable.building_a,
            R.drawable.building_b,

    };

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.browseActivityGalleryStylable);
        attr.recycle();
    }

    public int getCount() {

        return mImageIds.length;
    }

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        TextView browseActivityTitleTextView = (TextView)findViewById(R.id.browseActivityTitleTextView);

            if(position == 0){
                browseActivityTitleTextView.setText(" Α'");
            }
            if(position == 1){
                browseActivityTitleTextView.setText("  Β'");
            }           

        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(mImageIds[position]);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);  
        return imageView;
    }
}
}

When i swipe the gallery it changes to B’ as it should but when i swipe back it stays B’
Anyone knows how to fix this?

  • 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-02T10:08:43+00:00Added an answer on June 2, 2026 at 10:08 am

    Rather than changing the text from the BaseAdapter you should add a listener to the gallery and change it that way. You should also find the reference to the textview in your onCreate method.

    private TextView browseActivityTitleTextView;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_activity_layout);
    
    browseActivityTitleTextView = (TextView)findViewById(R.id.browseActivityTitleTextView);
    
    Gallery gallery = (Gallery) findViewById(R.id.browseActivityGallery);
    gallery.setAdapter(new ImageAdapter(this)); 
    gallery.setSpacing(0); 
    
    gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
    
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {              
    
                switch(position){
                case 0:
                    browseActivityTitleTextView.setText(" Α'");
                    break;
                case 1:
                    browseActivityTitleTextView.setText(" B'");
                    break;
                }
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {}
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have following column in SSRS Report. Column Name(Title) Mehta, Natasha(18)----its Title+(count) value
Hello I have this code to show image from folder in php : $handle
Hello i have the below code to open the gallery so that user picks
I have a requirement in that I want to implement an image gallery with
Hello guys i have the follow code on php return preg_replace_callback(#\{gallery: '(.+?)'\}#i, function($i) {
Hello i have 2 arrays and and i want to put them in a
hello I have my code that connects to my ftp server $conn_id = ftp_connect($ftp_server);
Hello I have this code class Triplets { public: int nVal1; int nVal2; NodeT
Hello I have the following code: if(_deviceSegmentCntrl.selectedSegmentIndex == 0) { deviceOne = [[NSString alloc]
Hello i have some simplified code here showing the problem i have. Basically i

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.