我正在使用
TabView
,在其中,我使用
Fragment
来加载每个标签。我想在用户接触到任何一个片段时获得
Touch
事件。
public MobileBankingFragment() {
// Required empty public constructor
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = (FragmentActivity) super.getActivity();
view = inflater.inflate(R.layout.fragment_mobile_banking, container, false);
alarm = new TimerReceiver();
init(view);
touchListener(view);
return view;
private void touchListener(View view) {
layout= (FrameLayout) view.findViewById(R.id.fragmentMobileBanking);
layout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(context, "you just touch the screen :-)", Toast.LENGTH_SHORT).show();
return true;
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(context, "you just touch the screen :-)", Toast.LENGTH_SHORT).show();
startTheTimerForTenSecond();
return true;
在这里,我尝试用两种方式获得触摸事件,一种是通过事件,另一种是通过布局的id,但我没有运气。这段代码没有出现错误,但也没有输出。