2011-11-10 75 views
1

我正在做一个Android应用程序,并有一个奇怪的问题。我需要一个ViewFlipper 5个选项卡。我做了一个5页按钮的页面布局。我用OnClickListener和翻转标签工作正常,但我需要setPressed(true)为一个按钮,我不能这样做。有重绘问题或某事。我在网上寻找解决方案,但没有其他人有这个问题?我做错了什么?设置按钮从ViewFlipper(Android)

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    factory = getLayoutInflater(); 
     skin = factory.inflate(R.layout.skin_tab_raspored, null); 

    vremelayout = (LinearLayout) skin.findViewById(R.id.vreme); 
    infolayout = (LinearLayout) skin.findViewById(R.id.info); 

     buttons[0] = (Button) skin.findViewById(R.id.pon); 
     buttons[1] = (Button) skin.findViewById(R.id.uto); 
     buttons[2] = (Button) skin.findViewById(R.id.sre); 
     buttons[3] = (Button) skin.findViewById(R.id.cet); 
     buttons[4] = (Button) skin.findViewById(R.id.pet); 

     buttons[0].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(0); 
       buttons[currentTab].setPressed(false); 
       currentTab = 0; 
       buttons[0].setPressed(true); 
      } 
     }); 
     buttons[1].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(1); 
       buttons[currentTab].setPressed(false); 
       currentTab = 1; 
       buttons[1].setPressed(true); 
      } 
     }); 
     buttons[2].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(2); 
       buttons[currentTab].setPressed(false); 
       currentTab = 2; 
       buttons[2].setPressed(true); 
      } 
     }); 
     buttons[3].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(3); 
       buttons[currentTab].setPressed(false); 
       currentTab = 3; 
       buttons[3].setPressed(true); 
      } 
     }); 
     buttons[4].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(4); 
       buttons[currentTab].setPressed(false); 
       currentTab = 4; 
       buttons[4].setPressed(true); 
      } 
     }); 

     buttons[0].setPressed(true); 

     add_time(); //adding content to vremelayout 

     flipper_info = new ViewFlipper(this); 

     flipper_info.addView(this.addContentToInfo(Dan.pon));//adding content to infolayout 
     flipper_info.addView(this.addContentToInfo(Dan.uto)); 
     flipper_info.addView(this.addContentToInfo(Dan.sre)); 
     flipper_info.addView(this.addContentToInfo(Dan.cet)); 
     flipper_info.addView(this.addContentToInfo(Dan.pet)); 

     infolayout.addView(flipper_info); 

     setContentView(skin); 
} 

回答

1

使用的setEnabled()insted的每clickListener内setPressed

  flipper_info.setDisplayedChild(0); 
      buttons[currentTab].setEnabled(true); 
      currentTab = 0; 
      buttons[0].setEnabled(false); 

OR

背景颜色变化使用切换按钮,它可以让你的开/关状态设置选择...在clickListener内切换状态。

+0

Tnx对此,但我不能使用这个。我需要更改bgd的按钮和使用选择器。无法进入选择器(项目)这个启用属性? – CoYoTe

+0

查看编辑答案 –

+0

雅ToggleButton的作品... TNX ...也必须使用启用和setChecked其他4个按钮导致需要一些单选按钮仍然按钮:P 毕竟,我看到我可能会使用单选按钮,购买添加他们我的皮肤:P – CoYoTe