最近Androidアプリの作成を触り始めた初心者です.
以前,TabActibityを用いてタブ画面を作製していたのですが現在は非推奨ということでFragmentTabHostを用いてタブ画面を作製し直そうと試みています.
テストとして簡単なテキストを表示するだけのタブ画面を作製したのですが,デバックを行うと画面が表示される前にエラーで停止してしまいます.
エラー内容は
「ソース添付にファイルChoreographer.classのソースが含まれていません.」
と表示されます.
以下がソースになります.
ソースに間違いがあるのでしょうか?
ご指摘いただければありがたいです.よろしくお願いします.
lang
1public class MainActivity extends FragmentActivity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_main); 7 FragmentTabHost host = (FragmentTabHost) findViewById(android.R.id.tabhost); 8 host.setup(this, getSupportFragmentManager(), R.id.content); 9 10 TabSpec tabSpec1 = host.newTabSpec("tab1").setIndicator("tab1"); 11 host.addTab(tabSpec1, PlaceholderFragment.class,null); 12 13 TabSpec tabSpec2 = host.newTabSpec("tab2").setIndicator("tab2");; 14 host.addTab(tabSpec2, PlaceholderFragment.class, null); 15 16 } 17 18 /* 19 * タブがクリックされた時に表示するFragment 20 */ 21 public static class PlaceholderFragment extends Fragment { 22 23 public PlaceholderFragment() { 24 } 25 @Override 26 public View onCreateView(LayoutInflater inflater, ViewGroup content, Bundle savedInstanceState) { 27 TextView textView = new TextView(getActivity()); 28 textView.setGravity(Gravity.CENTER); 29 textView.setText(getArguments().getString("name")); 30 31 return textView; 32 33 } 34 }
lang
1<android.support.v4.app.FragmentTabHost 2 xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@android:id/tabhost" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent"> 6 7 <LinearLayout 8 android:orientation="vertical" 9 android:layout_width="match_parent" 10 android:layout_height="match_parent"> 11 <!-- タブパネル操作のためのTabWidgetを配置 --> 12 <TabWidget 13 android:id="@android:id/tabs" 14 android:orientation="horizontal" 15 android:layout_width="match_parent" 16 android:layout_height="wrap_content" 17 android:layout_weight="0"/> 18 <!-- タブパネルを束ねるためのコンテナーを配置 --> 19 <FrameLayout 20 android:id="@android:id/tabcontent" 21 android:layout_width="0dp" 22 android:layout_height="0dp" 23 android:layout_weight="0"/> 24 <!-- タブが押された時に表示するコンテンツ領域(Fragment) --> 25 <FrameLayout 26 android:id="@+id/content" 27 android:layout_width="match_parent" 28 android:layout_height="0dp" 29 android:layout_weight="1"/> 30 31 </LinearLayout> 32 33</android.support.v4.app.FragmentTabHost> 34
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2014/12/27 07:44