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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:30:39+00:00 2026-05-24T13:30:39+00:00

I have a layout with an ImageSwitcher , a thumnail gallery, and a TextSwitcher

  • 0

I have a layout with an ImageSwitcher, a thumnail gallery, and a TextSwitcher. I would like the TextSwitcher to update text based on which thumbnail is selected. I have tried using a baseadapter to update the TextSwitcher in a similar manner to how the ImageSwitcher updates the images in the ImageView, but I am running into a wall here. Any help would be much appreciated! Thank you!

JAVA:

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.widget.Gallery.LayoutParams;


public class ImageSwitch1 extends Activity implements
        AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {

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

        setContentView(R.layout.imageswitcher);

        TextSwitcher mTextSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher1);
        mSwitcher = (ImageSwitcher) 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));


        mTextSwitcher.setFactory(this);
        mTextSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in));
        mTextSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out));

        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this));
        g.setOnItemSelectedListener(this);


    }

    public void onNothingSelected(AdapterView parent) {
    }

    public View makeView() {
        ImageView i = new ImageView(this);
        i.setBackgroundColor(0xFF000000);
        i.setScaleType(ImageView.ScaleType.FIT_CENTER);
        i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));

        return i;
    }

    private TextSwitcher mTextSwitcher;
    public class TextAdapter extends BaseAdapter{
        public TextAdapter(Context c){
            mContext = c;
        }
    public int getCount(){
        return mThumbIds.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 t = new TextView(mContext);
        t.setText(mText[position]);
        t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        t.setTextSize(36);
            return t;
        }
    private Context mContext;
    }    


    private ImageSwitcher mSwitcher;

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

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

        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);

            i.setImageResource(mThumbIds[position]);
            i.setAdjustViewBounds(true);
            i.setLayoutParams(new Gallery.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            i.setBackgroundResource(R.drawable.picture_frame);


            return i;



        }

        private Context mContext;



    }

    public void onItemSelected(AdapterView parent, View v, int position, long id) {
        mSwitcher.setImageResource(mImageIds[position]);
        mTextSwitcher.setText(mThumbIds[position]);
    }  





    private Integer[] mThumbIds = {
            R.drawable.image1_thumb, R.drawable.image2_thumb, R.drawable.image3_thumb,
            R.drawable.image4_thumb, R.drawable.image5_thumb};

    private Integer[] mImageIds = {
            R.drawable.image1, R.drawable.image2, R.drawable.image3,
            R.drawable.image4, R.drawable.image5};

    private Integer[] mText = {
        R.string.item1, R.string.item2, R.string.item3, R.string.item4, R.string.item5  
    };


}

XML:

<?xml version="1.0" encoding="utf-8"?>


    <FrameLayout android:id="@+id/FrameLayout1" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"> 

        <ImageSwitcher android:id="@+id/switcher"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
        </ImageSwitcher>

        <Gallery android:id="@+id/gallery"
            android:background="#55000000"
            android:layout_width="match_parent"
            android:gravity="center_vertical"
            android:spacing="16dp" android:unselectedAlpha="0.5" android:layout_height="80dp" />
        <TextSwitcher android:layout_width="match_parent" android:id="@+id/textSwitcher1" android:layout_height="wrap_content"></TextSwitcher>

    </FrameLayout>
  • 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-05-24T13:30:40+00:00Added an answer on May 24, 2026 at 1:30 pm

    You should be passing a string to mTextSwitcher.setText(mThumbIds[position]);
    instead change it to mTextSwitcher.setText(getText(mText[position]));

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

Sidebar

Related Questions

I have a layout requirement like below, Textview TextView ListView Edit Text Button Since
I have a layout similar to this: <div id=...><img src=...></div> and would like to
say I have layout like so: <div id=main> <div id=NormalContent> {some content which is
I have a Layout (using TableLayout, etc...) which works well. It seems like this:
I have Tab Layout that contains a TextView. I'd like to assign some text
I have this layout that works correctly, a relative layout with a text view
I have the layout of a configuration dialog in an XML like this: <?xml
I have a layout which I am inflating in order to dynamically add TableRows
I want to have layout, which is similar by structure to Thunderbird classic view
I have a layout which uses min-width and works great. So I came to

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.