2012-04-20 1 views
1

現在、私のアプリケーションをフラグメントに変換しており、多くの問題が発生しています。私はあなたの助けを借りてそれらをすべて解決できることを願っており、変換の特定の部分を解決したら投稿を編集します。Androidのフラグメントの問題(私のアプリケーションの変換)

第1の問題: AlertDialogs。ユーザーがボタンをクリックすると、ListViewアイテムの後に、AlertDialogが表示され、表示するアカウントを選択できます。私はFacebookとTwitterのためにこれを行う。しかし、二重構造は私を混乱させ、ListDialogは内容を別々に読み込むようです。

ので、活動のための私のコード:

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; 
      } 
     } 
    } 

} 

エラーがでます:

-

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

Syntax error, insert ";" to complete MethodDeclaration

を言う最初のダイアログ、上 .create();

Syntax error, insert ";" to complete ReturnStatement

Syntax error, insert ")" to complete MethodInvocation

Syntax error, insert "}" to complete ClassBody

- 最初showDialog();MyAlertDialogFragmentMyAlertDialogFragmentは解決できないという。 builder cannot be resolved:第二のダイアログを作成からbuilderに続い

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

さらに:第二ダイアログの初期化-In

。これは明らかに合法ですが、解決策はありません。

また、リソースディレクトリ名が無効であると不平を言っています。

私が直した最後の問題は:)。

私はABSを使用していますが、これはABSのタブの1つです。これは、フラグメントである必要があることを意味しますが、ActionBarは表示しません。

+0

構文エラーが発生しました。 – Blundell

答えて

0

皆さん、お手伝いをしてくれてありがとうございますが、しばらくの間解決されています。

しかし、ここに投稿するコードはたくさんあるので、誰かが知りたいのであれば:メッセージを撃って、私ができる限り手助けしようとします!

0

複数の構文エラーがあります。このトークン

後に期待したもの

識別子ザッツはあなたが維持するために非常に容易になるだろうが自分のクラスファイルにあなたのかけらを移動する必要があります

を意味します。

私は私がと思うが、それはブラウザでは難しいつのエラーを見つけることができます。

   default: 
        return; 
       } 
      } 
      getDialog.create(); 
     ) 
    } 

は次のようになります。

   default: 
        return; 
       } 
      } 
      getDialog.create(); 
     } 
    );   
} 

(はい1つのセミコロンの欠落)

+0

「フラグメントを独自のクラスファイルに移動する」とはどういう意味ですか?また、それはあなたが言ったようにその部分を編集する何も変更されませんでした... – DatBassie

+0

他の構文エラーがあるので、それはおそらく何も変更されません! – Blundell

+0

'public class SomeClass {}'の各クラスファイルは、自身の 'SomeClass.java'ファイルに移動できます。クラスのいずれかにコンパイルエラーがある場合、他のクラスには影響しません。 – Blundell

0

あなたを投稿アクティビティのコードですが、あなたの大会はSherlockから継承されていますフラグメント not SherlockFragmentActivity

FragmentFragmentActivityをご覧ください。

+0

私はすでにそれを解決しました。誰かが私にこれを行う正しい方法を採用するのを手伝ってくれました。しかし、これはSOの外にあったので、私は正しい答えをまだマークしていません。私があなたが言及したページを見て、ありがとう! – DatBassie