【发布时间】:2014-07-28 20:07:14
【问题描述】:
我不明白为什么这段代码没有运行:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_matchpage);
SeekBar sb1 = (SeekBar) findViewById(R.id.seek1);
sb1.setEnabled(false);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
sb1 将为空。 为什么?
【问题讨论】:
-
seek1不在activity_matchpage布局中。可能它在片段布局中。 stackoverflow.com/questions/23653778/… -
您有 ID 为 seek1 的组件吗?还有什么错误?
-
不,seek1 在匹配页中。
-
当我在按钮单击中运行此代码时,它运行:SeekBar sb1 = (SeekBar) findViewById(R.id.seek1); sb1.setEnabled(false);
-
为匹配页播种 xml 代码