[英]Java Android - setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})
When using the following code i keep getting errors, i know there is another way of using the onclick functions, android:onclick... but i prefer this 'cleaner' way. 当使用下面的代码我不断收到错误,我知道有另一种使用onclick函数的方法,android:onclick ...但我更喜欢这种'更清洁'的方式。
the id name of the textview is right but i keep getting this error with the onclicklistener. textview的id名称是正确的,但我继续使用onclicklistener获取此错误。
what am i doing wrong? 我究竟做错了什么?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
TextView text = (TextView) findViewById(usernameText);
text.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// Do some job here
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_screen, menu);
return true;
}`
The problem may be a jar that you imported that has an onClickListener... 问题可能是您导入的具有onClickListener的jar ...
Try add this: 尝试添加此:
text.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// Do some job here
}
});
without seeing your error, I'd guess that you probably imported the wrong OnClickListener. 没有看到你的错误,我猜你可能导入了错误的OnClickListener。 Make sure that it's the View one. 确保它是View one。
May be you should take your screenshot and upload here, but please looking for your code: 可能是您应该截取屏幕截图并上传到此处,但请查找您的代码:
Ensure you 确保你
import View.OnClickListener
TextView text = (TextView) findViewById(usernameText);
text.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// Do some job here
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.