我正在为赛艇运动员和桨手制作 Android 应用程序。有不同大小的船。就像只有一个桨手的 Kajak 和有 20 个桨手的龙舟。我正在尝试创建所有这些并仅显示我选择的典型船所需的那些。我的问题是我不能让微调器再次变得不可见和可见。我的代码是这样的:
public class DayTripActivity extends Activity {
private boolean visible = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.day_trip);
ScrollView scrollView = new ScrollView(this);
final LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout);
this.setContentView(scrollView);
for(int i = 0; i < 20; i++){
TextView tvCrew = new TextView(this);
tvCrew.setText("Crewmember "+i);
tvCrew.setId(ID_Crew_TEXTVIEW+i);
linearLayout.addView(tvCrew);
}
Button btndatePicker = new Button(this);
btndatePicker.setText("Make Drummer 2 invisible / visible");
btndatePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(visible){
linearLayout.findViewById(ID_DRUMMER_TEXTVIEW+1).setVisibility(View.VISIBLE);
}else{
linearLayout.findViewById(ID_DRUMMER_TEXTVIEW+1).setVisibility(View.GONE);
}
visible = !visible;
}
});
linearLayout.addView(btndatePicker);