我是 android studio 的新手,我不明白为什么当我开始使用搜索栏时我的应用程序崩溃了。有人可以帮我吗?
公共类 MainActivity 扩展 AppCompatActivity { SeekBar seeBar; //声明seekbar对象TextView textView, textView2; 列表视图简单列表视图;//为SeekBar声明成员变量 int离散; int开始= 50;int 起始位置 = 50; //进度跟踪器 int temp = 0; //为ViewStub声明对象ViewStub存根; 复选框复选框;列表视图lv; //声明Listview对象Button按钮; 查看视图;
public MainActivity() {
discrete = 0;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//declare viewstub object
stub = findViewById(R.id.viewStub1);
@SuppressWarnings("unused")
View inflated = stub.inflate();
stub.setVisibility(View.INVISIBLE);
//ViewStub logic
checkBox = findViewById(R.id.checkBox1);
//handle checkbox click event
checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if (isChecked) {
//remove objs from parent view to allow for child view objs
checkBox.setVisibility(View.GONE);
seekBar.setVisibility(View.GONE);
textView.setVisibility(View.GONE);
stub.setVisibility(View.VISIBLE);
}
}
});
//seekbar logic
textView = findViewById(R.id.textview);
textView = findViewById(R.id.textView2);
textView.setText(" Celsius at 0 degrees");
//set default view
seekBar = findViewById(R.id.seekbar);
seekBar.setProgress(start_position);
//create event handler for SeekBar
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (temp == 0) {
//for initial view result
//Toast.makeText(getBaseContext(), "Fahrenheit result: 32 degrees",
//Toast.LENGTH_SHORT).show();
textView2.setText("Fahrenheit result 32 degrees") ;
}
侃侃尔雅
拉风的咖菲猫
叮当猫咪
相关分类