在触摸第三个选项卡时,用户应该能够拨打 phone 电话。但是用户被重定向到触摸第二个选项卡时拨打电话,这是一个错误的选项卡

On touch of third tab,the user should be able to make phone call. But user is redirected to make call on touch of second tab which is a wrong tab

一个 activity 在选项卡栏上有三个选项卡。第一个和第二个选项卡用于显示网页,而第三个选项卡用于从应用程序进行 phone 调用。

情况: 当用户从第一个标签触摸第二个标签时,用户被重定向到 phone 呼叫应用程序,这不应该是它,然后它显示正确应该是网页。在触摸第三个选项卡时,它显示空白片段而不是进行 phone 调用。但是,当用户从第三个选项卡转到第二个选项卡时,它会显示正确的网页并且不会转移到 phone 应用程序。此外,当我从第一个选项卡转到第三个选项卡时,它会重定向用户进行 phone 调用。请注意,第三个选项卡仅用于进行 phone 调用。

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstancestate) {
    View layout = inflater.inflate(R.layout.fragment_myfragment, container, false);
    Bundle bundle = getArguments();
    web_personal = (WebView) layout.findViewById(R.id.webView);
    WebSettings webSettings = web_personal.getSettings();
    webSettings.setJavaScriptEnabled(true);

    if (bundle != null) {
        if (bundle.getString("activity") == "Personal") {
            if (bundle.getInt("position") == 0) {
                web_personal.loadUrl("http://www.xxxxxxx.in/inddddddn/view/26/Hexxx%20xxxxx/");
            } else if (bundle.getInt("position") == 1) {
                web_personal.loadUrl("http://www.xxxxxxxx.in/xxxxxx/view/34/Senior%20Citizen%2xxxxxx/");
            } else if (bundle.getInt("position") == 2) {
                web_personal.loadUrl("http://www.xxxxxxx.in/xxxxx/view/25/Personal%20xxxxx%2dddddd%20xxx/");
            }
        } else if (bundle.getString("activity") == "Home")
        {
            if (bundle.getInt("position") == 0) {
                web_personal.loadUrl("http://www.xxxxxxxxxx.in/");
            }
           else if (bundle.getInt("position") == 1) {
              web_personal.loadUrl("http://www.xxxxxxxxxxxx.in/contactus/");
            }
            else if(bundle.getInt("position") == 2)
            {
               Intent callIntent = new Intent(Intent.ACTION_CALL);
               callIntent.setData(Uri.parse("tel:0980000000"));
               startActivity(callIntent);
            }
        }
    }
        return layout;
    }

Layout of tab bar

如果我将webview 的loadUrl 函数用于显示网页而不是调用函数,那么它会根据If 子句中满足的条件显示网页。从而可以否定if子句的逻辑问题。

这个问题是因为缓存了视图。 如果您调试应用程序,您会看到当您到达第二个选项卡时将调用您的 onCreateView 和 onResume 所以有办法: 首先从 onCreateView

中删除代码
yourViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        ...
        @Override
        public void onPageSelected(int position) {
            if(position==2)
             //call your method in 3rd fragment
        }
    });