Shameless copy from SO (without a solution as of yet, obviously):

I am currently converting my app over to Fragments, and have run into a 
number of problems. I hope to be able to solve them all with your help, and 
will edit my post once I have solved a certain part of the conversion.

**First problem:**
AlertDialogs. When the user clicks on a button, maybe later a ListView 
item, they are presented with an AlertDialog to choose the account they 
want to see. I do this for Facebook and Twitter. However, the double 
construction confuses me, and ListDialog seems to load its content 
differently.

So, my code for the Activity:

    package bas.sie.Antonius;
    
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.v4.app.DialogFragment;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    import com.actionbarsherlock.app.SherlockFragment;
    
    public class External extends SherlockFragment implements 
OnClickListener {
    
    Button mBtnOuderPortaal;
    Button mBtnTeletop;
    Button mBtnWebmail;
    Button mBtnInfobord;
    Button mBtnTwitter;
    Button mBtnFacebook;
    Button mBtnYouTube;
    String URLhome;
    String Title;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    mBtnOuderPortaal = (Button) getActivity().findViewById(
    R.id.btnOuderPortaal);
    mBtnOuderPortaal.setOnClickListener(this);
    mBtnTeletop = (Button) getActivity().findViewById(R.id.btnTeletop);
    mBtnTeletop.setOnClickListener(this);
    mBtnWebmail = (Button) getActivity().findViewById(R.id.btnWebmail);
    mBtnWebmail.setOnClickListener(this);
    mBtnInfobord = (Button) getActivity().findViewById(R.id.btnInfobord);
    mBtnInfobord.setOnClickListener(this);
    mBtnTwitter = (Button) getActivity().findViewById(R.id.btnTwitter);
    mBtnTwitter.setOnClickListener(this);
    mBtnFacebook = (Button) getActivity().findViewById(R.id.btnFacebook);
    mBtnFacebook.setOnClickListener(this);
    mBtnYouTube = (Button) getActivity().findViewById(R.id.btnYouTube);
    mBtnYouTube.setOnClickListener(this);
    
    }
    
    void showDialog() {
    DialogFragment newFragment = MyAlertDialogFragment
    .newInstance(R.string.twitter_dialog_title);
    newFragment.show(getFragmentManager(), "dialog");
    }
    
    void showFBDialog() {
    DialogFragment newFragment = MyFBAlertDialogFragment
    .newInstance(R.string.facebook_dialog_title);
    newFragment.show(getFragmentManager(), "dialog");
    }
    
    public static class MyFBAlertDialogFragment extends DialogFragment {
    
    String URLhome;
    String Title;
    final CharSequence[] Facebook = { "Spot Antoniuscollege",
    "ACG Mediagroep" };
    
    public static MyAlertDialogFragment newInstance(int title) {
    MyAlertDialogFragment frag = new MyAlertDialogFragment();
    Bundle args = new Bundle();
    args.putInt("Kies Facebook-account", title);
    frag.setArguments(args);
    return frag;
    }
    
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt("title");
    
    return new AlertDialog.Builder(getActivity())
    .setTitle(title)
    .setItems(Facebook, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {
    switch (item) {
    case 0:
    URLhome = "http://m.facebook.com/spotcarmelcollege";;
    Title = "Facebook ACG Spot";
    
    Intent i = new Intent();
    i.setClass(getActivity(), MyWebView.class);
    i.putExtra("home", URLhome);
    i.putExtra("title", Title);
    startActivityForResult(i, 0);
    break;
    case 1:
    URLhome = "http://m.facebook.com/pages/ACG-Media/128125633969183";;
    Title = "Facebook ACG Media";
    
    Intent i1 = new Intent();
    i1.setClass(getActivity(), MyWebView.class);
    i1.putExtra("home", URLhome);
    i1.putExtra("title", Title);
    startActivityForResult(i1, 0);
    default:
    return;
    }
    }
    getDialog.create();
    )
    }
    
    }
    
    public static class MyAlertDialogFragment extends DialogFragment {
    
    final CharSequence[] Twitter = { "@ACGouda", "@Spot_ACG",
    "@ACGmediatheek" };
    String URLhome;
    
    public static MyAlertDialogFragment newInstance(int title) {
    MyAlertDialogFragment frag = new MyAlertDialogFragment();
    Bundle args = new Bundle();
    args.putInt("title", title);
    frag.setArguments(args);
    return frag;
    }
    
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt("title");
    
    return new AlertDialog.Builder(getActivity())
    .setTitle(title)
    s.setItems(Twitter,
    new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {
    switch (item) {
    case 0:
    URLhome = "https://mobile.twitter.com/#!/ACGouda";;
    
    Intent intent = new Intent(
    Intent.ACTION_VIEW);
    intent.setData(Uri.parse(URLhome));
    startActivity(intent);
    break;
    case 1:
    URLhome = "https://mobile.twitter.com/#!/Spot_ACG";;
    
    Intent intent1 = new Intent(
    Intent.ACTION_VIEW);
    intent1.setData(Uri.parse(URLhome));
    startActivity(intent1);
    break;
    case 2:
    URLhome = "https://mobile.twitter.com/#!/ACGmediatheek";;
    
    Intent intent2 = new Intent(
    Intent.ACTION_VIEW);
    intent2.setData(Uri.parse(URLhome));
    startActivity(intent2);
    break;
    default:
    return;
    }
    }
    });
    AlertDialog alert = builder.create();
    alert.show();
    }
    
    }
    
    @Override
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnFacebook:
    showFBDialog();
    break;
    case R.id.btnTwitter:
    showDialog();
    break;
    case R.id.btnInfobord:
    URLhome = 
"http://carmelcollegegouda.nl/site_ant/index.php?option=com_content&view=article&id=182&Itemid=131&lang=nl";;
    Title = "Infobord";
    
    Intent bord = new Intent();
    bord.setClass(getActivity(), MyWebView.class);
    bord.putExtra("home", URLhome);
    bord.putExtra("title", Title);
    startActivityForResult(bord, 0);
    break;
    case R.id.btnOuderPortaal:
    URLhome = "https://portaal.mijnsom.nl/login/ccg";;
    Title = "Onderwijsportaal";
    
    Intent portaal = new Intent();
    portaal.setClass(getActivity(), MyWebView.class);
    portaal.putExtra("home", URLhome);
    portaal.putExtra("title", Title);
    startActivityForResult(portaal, 0);
    break;
    case R.id.btnTeletop:
    URLhome = "http://antoniuscollege.teletop.nl/";;
    
    Intent teletop = new Intent(Intent.ACTION_VIEW);
    teletop.setData(Uri.parse(URLhome));
    startActivity(teletop);
    break;
    case R.id.btnMail:
    URLhome = "https://webmail.carmelcollegegouda.nl/";;
    Title = "Webmail";
    
    Intent mail = new Intent();
    mail.setClass(getActivity(), MyWebView.class);
    mail.putExtra("home", URLhome);
    mail.putExtra("title", Title);
    startActivityForResult(mail, 0);
    break;
    case R.id.btnYouTube:
    URLhome = 
"http://m.youtube.com/results?search_query=Antoniuscollege&oq=Antoniuscollege&aq=f&aqi=&aql=&gs_l=youtube-psuggest.3...4430l12422l0l12750l31l31l9l1l2l0l122l1657l20j1l21l0.";;
    
    Intent YT = new Intent();
    YT.setClass(getActivity(), MyWebView.class);
    YT.putExtra("home", URLhome);
    startActivityForResult(YT, 0);
    break;
    }
    }
    }
    
    }

The errors are at:

-`.create();` on the first dialog, which says 

`Syntax error on token "create", Identifier expected after this token`

`Syntax error, insert ";" to complete MethodDeclaration`

`Syntax error, insert ";" to complete ReturnStatement`

`Syntax error, insert ")" to complete MethodInvocation`

`Syntax error, insert "}" to complete ClassBody`


-`MyAlertDialogFragment` in the first `showDialog();`, saying that 
`MyAlertDialogFragment` cannot be resolved.


-In the initialization of the second Dialog:

`Syntax error on token ".", delete this token`

`The method setItems(CharSequence[], new 
DialogInterface.OnClickListener(){}) is undefined for the type 
External.MyFBAlertDialogFragment.MyAlertDialogFragment`

`Type mismatch: cannot convert from AlertDialog.Builder to Dialog`

Then also on the `builder` from creating the second Dialog: `builder cannot 
be resolved`. This one is obviously legit, but I have no solution.

It's also complaining about the resource directory name being invalid.

The last problem I just fixed :).

I'm using ABS, but this is one of the tabs in ABS. This means it needs to 
be a Fragment, but not show the ActionBar.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to