2011-08-09 18 views
2

ここでかなり簡単な質問ですが、私はまだJavaスーパーユーザーではありません。Viewflipperで動的にテキストビューを変更

私はいくつかの画像を提供するためにViewFlipperを使用しており、各画像に固有のテキストを含むスライド引出しを使用しています。スライドショーのテキストを、現在表示されている子ビューに依存する特定の文字列に変更したいと思います。ここ はXMLです:ここ

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <Button 
      android:id="@+id/previous" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Prev" /> 
     <Button 
      android:id="@+id/next" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Next" /> 
    </LinearLayout> 
    <ViewFlipper 
     android:id="@+id/flipper" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image1"></ImageView> 
     <ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image2"></ImageView> 
      </ViewFlipper> 
</LinearLayout> 

は、javaです:

public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 


      flipper = (ViewFlipper)findViewById(R.id.flipper); 
      next = (Button) findViewById(R.id.next); 
      previous = (Button) findViewById(R.id.previous); 
      imageview1 = (ImageView)findViewById(R.id.imageView1); 
      imageview2 = (ImageView)findViewById(R.id.imageView2); 



      next.setOnClickListener(this); 
      previous.setOnClickListener(this); 
     } 



     @Override 
     public void onClick(View v) { 
      if (v == next) { 
       flipper.setInAnimation(inFromRightAnimation()); 
       flipper.setOutAnimation(outToLeftAnimation()); 
       flipper.showNext(); 
      } 

      if (v == previous) { 
       flipper.setInAnimation(inFromLeftAnimation()); 
       flipper.setOutAnimation(outToRightAnimation()); 
       flipper.showPrevious(); 

      } 
      } 

私は答えは本当に明白であると確信しているが、私は....おかげであなたの助けを必要とする理由です!

+0

あなたのslidedrawerコードはどこですか? – Jack

答えて

2

showNext()showPrevious()に電話するときは、TextViewを一致するように更新してください。

+0

ありがとう! – benbeel

関連する問題