我只能获得一个自定义按钮来打开URL

时间:2015-08-17 20:34:59

标签: android android-fragments

我的应用程序存在一些问题,我一直试图打开不同的网址,具体取决于您点击的自定义按钮,但我似乎只能将Google+转到工作,任何人都可以帮我解决为什么我有这个问题...

这是我的片段:

public static void showAbout(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog().show(ft, "dialog_about");
}

public static class AboutDialog extends DialogFragment {

    String url1 = "https://plus.google.com/+AjappsUk";

    public AboutDialog() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout aboutBodyView = (LinearLayout) layoutInflater.inflate(R.layout.dialog_about, null);
        com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton google_plus = (com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton)aboutBodyView.findViewById(R.id.google_plus);
        google_plus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url1));
                startActivity(i);
            }

        });

        return new AlertDialog.Builder(getActivity())
                .setView(aboutBodyView)
                .create();
    }

}

//------------------------------------------------------------------------

public static void showAbout2(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog2().show(ft, "dialog_about");
}

public static class AboutDialog2 extends DialogFragment {

    String url2 = "https://plus.google.com/+AjappsUk";

    public AboutDialog2() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout aboutBodyView = (LinearLayout) layoutInflater.inflate(R.layout.dialog_about, null);
        com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton facebook = (com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton)aboutBodyView.findViewById(R.id.facebook);
        facebook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url2));
                startActivity(i);
            }

        });

        return new AlertDialog.Builder(getActivity())
                .setView(aboutBodyView)
                .create();
    }

}

//------------------------------------------------------------------------

public static void showAbout3(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog3().show(ft, "dialog_about");
}

public static class AboutDialog3 extends DialogFragment {

    String url3 = "https://twitter.com/AjApps_";

    public AboutDialog3() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout aboutBodyView = (LinearLayout) layoutInflater.inflate(R.layout.dialog_about, null);
        com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton twitter = (com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton)aboutBodyView.findViewById(R.id.twitter);
        twitter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url3));
                startActivity(i);
            }

        });

        return new AlertDialog.Builder(getActivity())
                .setView(aboutBodyView)
                .create();
    }

}

//------------------------------------------------------------------------

public static void showAbout4(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog4().show(ft, "dialog_about");
}


public static class AboutDialog4 extends DialogFragment {

    String url4 = "https://plus.google.com/+AjappsUk";

    public AboutDialog4() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout aboutBodyView = (LinearLayout) layoutInflater.inflate(R.layout.dialog_about, null);
        com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton website = (com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton)aboutBodyView.findViewById(R.id.website);
        website.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url4));
                startActivity(i);
            }

        });

        return new AlertDialog.Builder(getActivity())
                .setView(aboutBodyView)
                .create();
    }

}

//------------------------------------------------------------------------

这是我的XML:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal">

    <com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/twitter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_icon="@drawable/android"
        android:background="@drawable/button_pressed2"
        fab:fab_colorNormal="@color/greens"
        fab:fab_colorPressed="@color/greens_pressed"
        android:layout_gravity="center_horizontal"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/website"
        android:layout_toStartOf="@+id/website" />

    <com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/website"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_icon="@drawable/web"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/facebook"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_icon="@drawable/facebook"
        fab:fab_colorNormal="@color/facebook"
        fab:fab_colorPressed="@color/facebook_pressed"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/google_plus"
        android:layout_toEndOf="@+id/google_plus" />

    <com.ajapps.systemtools.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/google_plus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_icon="@drawable/googleplus"
        fab:fab_colorNormal="@color/google"
        fab:fab_colorPressed="@color/google_pressed"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

快速浏览一下您的代码:您将url2和url4设置为与url1相同,这是一个谷歌加链接......这是问题吗?