如何在LinearLayout
中一次添加事件OnTouchListener
和OnclickListener
?如何在Linear Layout中一次添加OnTouchListener和OnClickListener?
這裏是我的代碼,但不工作
final LinearLayout llTimeTable=(LinearLayout) findViewById(R.id.llSehriIftar);
llTimeTable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Ramadandate.class);
startActivity(intent);
}
});
llTimeTable.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
llTimeTable.setBackgroundColor(Color.rgb(51, 51, 255));
break;
case MotionEvent.ACTION_UP:
// set color back to default
llTimeTable.setBackgroundColor(Color.rgb(76, 106, 225));
break;
}
return true;
}
});
但是,當我只用OnclickListener
它的工作原理,當我只用onTouch
方法它的工作原理,但兩者在同一時間不能正常工作。
你的概念不清晰觸摸和點擊,請閱讀第一 –
http://stackoverflow.com/questions/11578718/how-to-combine-onclicklistener-and-ontouchlistener-for-an-imagebutton – Karthik
您可能需要看看這個。我認爲這有助於掌握onTouch vs onClick http://stackoverflow.com/a/9123001/1239911 – Amt87