【发布时间】:2017-11-16 09:28:43
【问题描述】:
这是我的代码...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.textView);
text.setText("Application Created");
btn1 = (Button) findViewById(R.id.Mybutton);
btn1.setOnClickListener(this);
btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(this);
btn1.setOnLongClickListener(**this**);*(Error Generated here)*
}
public boolean onLongClick( View v)
{
return true;
}
我正在尝试在两个以上的按钮上使用长按侦听器,并通过使用 switch case 在一个方法(公共布尔 onLongClick(View v))中处理它们。我尝试了我的代码,但是当我通过 btn1.setOnLongClickListener(this); "this" in the括号" 时生成错误,我正在同一个类中处理此事件。
【问题讨论】:
-
在 longClick 中使用 switch case , switch(view.getId()) 并用它们各自的 ID 识别你的按钮
-
非常感谢先生!试图帮助我,但我遇到了错误
-
btn1.setOnLongClickListener(this);*(Error Generated here)* 这部分你能帮我做这部分吗
-
让你的类实现 onLongClickListener
标签: android event-handling onclicklistener onlongclicklistener android-event