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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:21:13+00:00 2026-06-06T03:21:13+00:00

I have a viewflipper that I want to populate with the same layout multiple

  • 0

I have a viewflipper that I want to populate with the same layout multiple times, but in each layout I need to display different text and a different background image, based on some array. So far, it just replaces the first view every time with the different text/ backgrounds. For now, I’ve predefined the arrays. Any help is greatly appreciated.

The code for the viewflipper:

private int numcards = 3;
private String creditnum[] = {"***********2451", "***********2452", "***********2453"};
private int carddraw[] = {R.drawable.fullcredit_blue, R.drawable.fullcredit_green, R.drawable.fullcredit_silver};

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.show_cards);
    viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);

    gestureDetector = new GestureDetector(this);
    for (int i = 0; i < numcards; i++)
    {
        viewFlipper.addView(View.inflate(this, R.layout.card_scroll_item, null), new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/credit.otf");
        Button creditbtn = (Button) findViewById(R.id.credit_button);
        creditbtn.setBackgroundResource(carddraw[i]);
        TextView txtname = (TextView) findViewById(R.id.credit_type);
        txtname.setText("Visa");
        TextView txtnumber = (TextView) findViewById(R.id.credit_number);
        txtnumber.setText(creditnum[i]);
        txtnumber.setTypeface(tf);

    }
}

And the xml for the view that i’m inflating:

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


<Button
    android:id="@+id/credit_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:layout_marginTop="104dp" android:layout_marginBottom="220dp" android:layout_alignParentBottom="true"/>

<TextView
    android:id="@+id/credit_type"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/credit_button"
    android:layout_alignTop="@+id/credit_button"
    android:layout_marginRight="22dp"
    android:layout_marginTop="21dp"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" android:typeface="normal"/>



<TextView
    android:id="@+id/credit_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/credit_button"
    android:layout_alignRight="@+id/credit_type"
    android:layout_centerVertical="true"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginLeft="15dp" android:layout_marginBottom="30dp"/>

  • 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-06T03:21:15+00:00Added an answer on June 6, 2026 at 3:21 am

    The problem is that you aren’t holding on to the view you’re adding, so findViewById is being called on the Activity’s content view, which will always return the first view with that ID. Try this:

    View view = View.inflate(this, R.layout.card_scroll_item, null);
    viewFlipper.addView(view);
    Button creditbtn = (Button) view.findViewById(R.id.credit_button);
    creditbtn.setBackgroundResource(carddraw[i]);
    TextView txtname = (TextView) view.findViewById(R.id.credit_type);
    txtname.setText("Visa");
    TextView txtnumber = (TextView) view.findViewById(R.id.credit_number);
    txtnumber.setText(creditnum[i]);
    txtnumber.setTypeface(tf);
    

    Those layout params are redundant, as you have them defined in your XML.

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

Sidebar

Related Questions

I have a ViewFlipper that is transitioned between each view, I want to draw
What I need: I need to have different WebViews inside a ViewFlipper and then
I need some help. In my android app I have a ViewFlipper that contains
I have a TabHost that has two ViewFlippers, and inside each ViewFlipper are three
I have got a ViewFlipper that gets populated with multiple views, that are actually
I have a ViewFlipper that presents 3 different views. Is it possible to have
I have a ViewFlipper with 3 children. I want to be able to display
I have a ScrolLView that wraps a ViewFlipper. The content in the ViewFlipper is
Have a network location that shows paths in the 8.3 short format. I need
I have a ViewFlipper in my Activity that is used as a footer view

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.