0

タブを動的に作成および削除しようとしています。通常、TabSpec で作成されたタブごとにアクティビティを設定する必要があります。しかし、タブが動的に作成されたときにどうすればよいでしょうか? ここでは、フレーム レイアウトを使用してタブ コンテンツを表示しています。タブのコンテンツを設定して同じアクティビティを使用しようとすると、テキストが重なってしまいます。ここでは、EditText ビューからテキストを読み取り、それをタブ コンテンツとして設定する必要があります。そのコンテンツは、そのタブに移動するたびに表示される必要があります。

4

1 に答える 1

5

これを試して

protected TabHost tabs;

// ...

/**
 * Init tabs.
 */
private void initTabs() {
tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
tabs.setBackgroundResource(R.drawable.bg_midgray);

TabHost.TabSpec spec;

// Location info
txtTabInfo = new TextView(this);
txtTabInfo.setText("INFO");
txtTabInfo.setPadding(0, 0, 0, 0);
txtTabInfo.setTextSize(14);
txtTabInfo.setBackgroundResource(R.drawable.bg_tab_left_inactive_right_inactive);
txtTabInfo.setTextColor(Color.DKGRAY);
txtTabInfo.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP);
txtTabInfo.setHeight(39);
spec = tabs.newTabSpec("tabInfo");
spec.setContent(R.id.tabInfo);
spec.setIndicator(txtTabInfo);
tabs.addTab(spec);

// Maps
txtTabMap = new TextView(this);
txtTabMap.setText("MAP");
txtTabMap.setTextSize(14);
txtTabMap.setPadding(0, 0, 0, 0);
txtTabMap.setBackgroundResource(R.drawable.bg_tab_middle_inactive_right_active);
txtTabMap.setTextColor(Color.DKGRAY);
txtTabMap.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP);
txtTabMap.setHeight(39);
spec = tabs.newTabSpec("tabMap");
spec.setContent(R.id.tabMap);
spec.setIndicator(txtTabMap);
tabs.addTab(spec);

tabs.setCurrentTab(0);

tabs.setOnTabChangedListener(this);
}

// ...
于 2014-07-24T05:52:31.753 に答える