"wrong first argument type. Found: 'android.widget.Compoundbutton.oncheckedchangelistener', required: 'android.content.context'"

"wrong first argument type. Found: 'android.widget.Compoundbutton.oncheckedchangelistener', required: 'android.content.context'"

此代码:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Hours_array, R.layout.MainActivity);       
adapter.setDropDownViewResource(R.layout.MainActivity);  
Hrs.setAdapter(adapter);

第一行代码中的"this"抛出这个错误:

wrong first argument type. Found: 'android.widget.Compoundbutton.oncheckedchangelistener', required: 'android.content.context

我正在尝试使用开关将包含小时数的微调器条目从常规时间更改为军事时间。

如果你能帮忙,请帮忙。非常感谢!

当您在 oncheckedchangelistener 中引用 this 时,它将引用 oncheckedchangelistener 对象而不是 MainActivity

而不是

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Hours_array, R.layout.MainActivity); 

使用

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(MainActivity.this, R.array.Hours_array, R.layout.MainActivity);