0

シナリオ:ViewFlipperと2つのRelativeLayoutを含むビューlobby4.xmlがあります。両方のrelativelayoutには、buttonTOGというボタンがあり、これを使用して1つのrelativelayoutから別のrelativelayoutに切り替えることができます。コードは次のとおりです。

    @Override
public void onCreate(Bundle savedInstanceState) {


  super.onCreate(savedInstanceState);
  setContentView(R.layout.lobby4);
  Context context = getApplicationContext();
  final ViewFlipper vf = (ViewFlipper) findViewById( R.id.viewFlipper );
  bTOG=(Button)findViewById(R.id.buttonTOG);
  final Activity the_a = this;
  final Context static_ctx = this.getApplicationContext();
    bTOG.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
          String buttons=bTOG.getText().toString();
          bTOG=(Button)findViewById(R.id.buttonTOG);
          String mystring = getResources().getString(R.string.Playbyemail);
          if( buttons!=null && buttons.compareTo(mystring)==0){
              vf.showPrevious();  
          }else{
              vf.showNext();  
          }


      }
    });


}

bTOGを2回クリックしても、onClickイベントはありません。だから私はonclickを登録する必要があると思いますか?

4

1 に答える 1

0

十分なはずです:

@Override
public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.lobby4);
final ViewFlipper vf = (ViewFlipper) findViewById( R.id.viewFlipper );
bTOG=(Button)findViewById(R.id.buttonTOG);
  bTOG.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
      if(vf.getDisplayedChild() == 0){
vf.setDisplayedChild(1);
}else{
vf.setDisplayedChild(0)
}


  }
 });


}
于 2012-12-19T19:03:27.847 に答える