2015-08-17 38 views
0

我有一個與我的應用程序有點問題,我一直試圖打開不同的URL取決於你點擊自定義按鈕,但我只能似乎得到Google+的工作,任何人都可以幫我解決爲什麼我有這個問題...我只能得到我的自定義按鈕之一來打開一個URL

這是我的片段:

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> 

回答

0

快速瀏覽一下你的代碼:你有兩個url2和url4設置爲相同的url1,這是一個谷歌加鏈接...是這樣的問題?

+0

不,我改變他們爲url1,url2,url3和url4只是爲了看看是否有幫助,它並沒有不幸,我點擊按鈕,並沒有得到任何答覆,即使我已經通過編號設置他們 –

+0

我只能得到其中一人每次工作 –

相關問題