我需要在单击选项卡时显示进度对话框,
我的代码ID
public class SIPTabWidget extends TabActivity{
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
final Resources res = getResources(); // Resource object to get Drawables
final TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ListContacts.class);
// Initialize a TabSpec for each tab and add it …Run Code Online (Sandbox Code Playgroud) 我问我们是否可以在另一个类的tabhost上调用setCurrentTab而不是包含tabhost和tabspecs的类?
我们可以放
tabHost.setCurrentTab(1);
Run Code Online (Sandbox Code Playgroud)
在另一个班级而不是这个班级:
public class Main extends TabActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("", "Welcome in Main");
setContentView(R.layout.tab);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); // Le TabHost a des Tabs
TabSpec firstTabSpec = tabHost.newTabSpec("tid1"); // TabSpec: new tab - TabSpec : setContent to the tab
firstTabSpec.setIndicator("Informations", getResources().getDrawable(R.drawable.database)).setContent(new Intent(this,FirstTab.class));
tabHost.addTab(firstTabSpec);
TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
secondTabSpec.setIndicator("Graphiques", getResources().getDrawable(R.drawable.chart)).setContent(new Intent(this,SecondTab.class));
tabHost.addTab(secondTabSpec);
TabSpec thirdTabSpec = tabHost.newTabSpec("tid1"); // tid1 is firstTabSpec Id (used to access outside)
thirdTabSpec.setIndicator("Réglages", getResources().getDrawable(R.drawable.settings)).setContent(new Intent(this,ThirdTab.class));
tabHost.addTab(thirdTabSpec);
}
}
Run Code Online (Sandbox Code Playgroud)
我们可以把它变成静态变量吗?我们怎样才能做到这一点?
感谢您的关注!
让我解释一下我的应用程序的结构,在我的应用程序中,我有3个使用Fragments实现的主要选项卡.其中一个主选项卡在其片段中包含3个子选项卡,一个子选项卡包含 listview.现在我想在选择列表中的项目时启动活动.
这是列表视图的onItemClickListener:
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View view, int position,long id)
{
RecordObjects obj=(RecordObjects)lv.getItemAtPosition(position);
String name=obj.getName();
String url=obj.getUrl();
intent=new Intent(getActivity(),player.class);
intent.putExtra("task","Draft");
intent.putExtra("name",name);
intent.putExtra("read_path",url);
startActivityForResult(intent, 0);
}
});
Run Code Online (Sandbox Code Playgroud)
我点击列表项时得到的错误是:
05-09 16:19:07.723: D/PhoneWindow(7043): couldn't save which view has focus because the focused view android.widget.LinearLayout@44ecc1d8 has no id.
05-09 16:19:07.741: D/AndroidRuntime(7043): Shutting down VM
05-09 16:19:07.741: W/dalvikvm(7043): threadid=3: thread exiting with uncaught exception (group=0x4001b188) …Run Code Online (Sandbox Code Playgroud) 我正在开发FragmentsTabs,任何人都可以告诉我,如何为每个选项卡维护单独的backstack ......?提前感谢.
我可以在Dialog中使用TabHost吗?我的应用程序扩展了活动(非Tab-Activity).另一个问题是如何在按下选项卡时调用函数.
请给我一个简单的例子.
提前致谢
我正在编写一个使用许多片段的应用程序.我使用了ActionBarSherlock(带ActionBar).为了解决bug#240,我决定切换一个功能正常的实现来使用ActionBarSherlock和TabHost.经过半个小时的工作,它工作正常,除了我在页面之间滑动:相应的选项卡被选中,但没有居中,往往甚至看不到,因此用户无法看到选择了哪个选项卡.

在图片中,您可以看到可见片段("WEEKLY S .."),但标签只有一半可见.下一次滑动只会使"WEEKLY S ..."看起来像"CALENDAR EVENTS",除非我手动滑动TabWidget,否则我不知道选择了哪个Tab.
这是我的activity_main.xml:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tabStripEnabled="true"
android:orientation="horizontal" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
而我的TabsAdapter与Jake Wharton的FragmentTabsPager示例相同.
欢迎任何建议!
android horizontal-scrolling android-tabhost android-viewpager actionbarsherlock
我想将tabhost的默认蓝色更改为红色.
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
<item name="android:tabWidgetStyle">@drawable/tab_indicator_holo</item>
</style>
Run Code Online (Sandbox Code Playgroud)
tab_indicator_holo.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_holo" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_holo" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />
</selector> …Run Code Online (Sandbox Code Playgroud) 有没有人遇到过这个错误?
现在我正在尝试从android/eclipse中的标签主机的第一个标签切换到第二个标签.但是在运行模拟器后显示为应用程序Tab_testing意外停止"请稍后重试
任何人都可以找到解决方案吗?
请在下面找到我的来源.
主要来源
public class Tab_testingActivity extends TabActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, Activity_1.class);
spec = tabHost.newTabSpec("first").setIndicator("First").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Activity_2.class);
spec = tabHost.newTabSpec("second").setIndicator("Second").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
Run Code Online (Sandbox Code Playgroud)
*活动_1* …