2011-08-09 120 views
2

这里很简单的问题,但我还不是java超级用户。在Viewflipper中动态更改textview

我正在使用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

你的滑动代码在哪里? – Jack

回答

2

当您拨打showNext()showPrevious()时,请更新您的TextView以匹配。

+0

谢谢你! – benbeel