一段时间内,点击监听器无法在android中正常工作。挂断电话,应用程序无响应

时间:2019-01-31 07:08:18

标签: android button onclicklistener

enter image description here

有时它会正常工作,但有时会变得反应迟钝,如图所示,请帮助我。谢谢

我正在使用底部导航器,并且我有多个片段片段包含其余的API调用,并且基于结果,我正在创建一些布局,按钮并为其提供点击侦听器

 private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
        = new BottomNavigationView.OnNavigationItemSelectedListener() {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        switch (item.getItemId()) {

            case R.id.navigation_home:
                SearchFragment dashBoardFragment = new SearchFragment(false, getApplicationContext());
                transaction.replace(R.id.linear_content, dashBoardFragment);
                transaction.commit();
                return true;
            case R.id.navigation_location:
                LocationFragment locationFragment = new LocationFragment(getApplicationContext());
                transaction.replace(R.id.linear_content, locationFragment);
                transaction.commit();
                return true;
            case R.id.navigation_search:
                SearchFragment dashBoardFragment1 = new SearchFragment(true, getApplicationContext());
                transaction.replace(R.id.linear_content, dashBoardFragment1);
                transaction.commit();
                return true;
            case R.id.navigation_profile:
                ProfileFragment profileFragment = new ProfileFragment();
                transaction.replace(R.id.linear_content, profileFragment);
                transaction.commit();
                return true;
        }
        return false;
    }
};

某些按钮在点击监听器上具有这样的效果

  phoneClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null));
                startActivity(intent);
            }
        });
        final String location = obj.getLoc();
        chk_location.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                        Uri.parse("http://maps.google.com/maps?daddr=" + location));
                intent.setPackage("com.google.android.apps.maps");
                startActivity(intent);
            }
        });

0 个答案:

没有答案