我的应用程序的文本编辑器允许用户打开和编辑文件,我想将文件作为TabHost中的新选项卡打开,因此可以打开多个文件。如何将EditText添加到新创建的Tab?这是我在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());
答案 0 :(得分: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;
}
});