OnLongClickListiner不起作用

时间:2017-04-09 11:52:09

标签: java android onlongclicklistener

代码抛出编译时错误:

GnuTLS

代码:

Class 'Anonymous class derived from OnLongClickLister' is not abstract and does not override abstract method onLongClick(View) in OnLongClickListener

1 个答案:

答案 0 :(得分:0)

你没有覆盖正确的方法。它是onLongClick,而不是OnLongClick。见下文:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button amitsbutton = (Button) findViewById(R.id.amitsbutton);

        amitsbutton.setOnClickListener(
                new Button.OnClickListener() {
                    public void onClick(View v) {
                        TextView amitstext = (TextView) findViewById(R.id.amitstext);
                        amitstext.setText("Small click is working");
                    }
                }
        );

        amitsbutton.setOnLongClickListener(
                new Button.OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        TextView amitstext = (TextView) findViewById(R.id.amitstext);
                        amitstext.setText("long click is also working ");
                        return true;
                    }
                }
        );