1

次のコードを使用して複数の TextView を CommonsWare ViewSwiper に追加していますが、TextView が重複しています。

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

    }

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" />

これを行う適切な方法は何ですか。

4

1 に答える 1

0

他の誰かが助けを必要とする場合に備えて、次のコードを使用して動作させました。

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

    }
于 2012-01-23T10:36:30.570 に答える