1

I am using the following code to add multiple TextViews to CommonsWare ViewSwiper but I see Overlapping TextViews:

    for (int i = 0; i < 10; i++){

        LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = vi.inflate(R.layout.c_layout, null);

        // fill in any details dynamically here
        TextView textView = (TextView) v.findViewById(R.id.myTextView);
        textView.setText("This is text " + i);

        swiper.addView(textView);

    }

Following is the layout for c_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

what should be the proper way of doing this.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Ali
  • 1,648
  • 2
  • 26
  • 48

1 Answers1

0

Used the following code to get it to work, In case someone else needs help:

    ViewSwiper swiper = (ViewSwiper)findViewById(R.id.swiper); 

    ViewFlipper flipper = swiper.getFlipper();

    for (int i = 0; i < 10; i++){

        LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = vi.inflate(R.layout.trivia_text, null);

        // fill in any details dynamically here
        TextView textView = (TextView) v.findViewById(R.id.triviaText);
        textView.setId(i);
        textView.setText("This is text " + i);

        flipper.addView(textView);

    }
Ali
  • 1,648
  • 2
  • 26
  • 48