0

アプリのテキスト エディターを使用すると、ユーザーはファイルを開いて編集できます。ファイルを TabHost の新しいタブとして開き、複数のファイルを開くことができるようにしたいと考えています。新しく作成したタブに EditText を追加するにはどうすればよいですか? これは私が onCreate() で試したものです

TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();
        EditText editor = new EditText(this);
        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        spec1.setContent(editor.getId());
        spec1.setIndicator("Tab 1");

問題は `spec1.setContent(editor.getId()); だと思います。

4

1 に答える 1

1

ID(ちなみに定義されていませんでした)をレイアウトIDとして設定しようとしました。そのようには機能しません。試す:

TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();
        EditText editor = new EditText(this);
        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        spec1.setIndicator(editor); 

これがあなたが望むものなら。あなたも試すことができます:

TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
            tabHost.setup();
            final EditText editor = new EditText(this);
            TabSpec spec1=tabHost.newTabSpec("Tab 1");
            spec1.setContent(new TabHost.TabContentFactory(){
                 public View createTabContent(String tag){
                     return editor;
                 }
             });
于 2013-07-10T23:48:48.227 に答える