我正在使用Android Studio制作App。
我有一个
public class MainActivity extends Activity implements View.OnClickListener, OnCheckedChangeListener
我需要在MainActivity中添加“ AppCompatActivity”。
我在Internet上进行了搜索,发现只有一个可以用于扩展。
所以我改为
public class MainActivity extends Activity implements View.OnClickListener, OnCheckedChangeListener, AppCompatActivity
这和AppCompatActivity出现错误“此处需要接口”。
我该如何解决这个问题?
答案 0 :(得分:5)
AppCompatActivity
是一个类,不是接口,因此您不能使用implements
关键字来继承AppCompatActivity
您需要使用extends
关键字来继承AppCompatActivity
类
使用此
public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnCheckedChangeListener
代替
public class MainActivity extends Activity implements View.OnClickListener, OnCheckedChangeListener, AppCompatActivity
答案 1 :(得分:0)
The 'Interface expected here' occurs when you implement a class, not an interface.
AppCompatActivity
is a class which you are not able to implement.
I don't know why you want to extend from Activity
in addition toAppCompatActivity
, AppCompatActivity
inherits from Activity
already.
AppCompatActivity > FragmentActivity > SupportActivity > Activity
Just write:
public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnCheckedChangeListener {
There is no need to extend Activity
for you when you do it like that.