English 中文(简体)
将标签添加到制表位主机
原标题:android add tab to tabhost

我正使用代码在标签标签上添加标签, 但会在第一行到最后一行时崩溃, spec. set Content( intent) 。 调试器说不要太多 。 谢谢 。

来自登记局,

Intent intentIOS = new Intent(Registrat.this, TabBar_Activity.class);
Bundle bundle = new Bundle();
bundle.putString("idusuari", idusuari);
String appid = null;

来自TabBar的活性,

private void setTabs(String numTabs){

        addTab(tab1name, "tab1", myTab1.class);
        addTab(tab2name, "tab2", myTab2.class);
}

private void addTab(String labelId, String imageName, Class<?> c)
    {
      TabHost tabHost = getTabHost();
          Intent intent = new Intent(this, c);
          TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

          View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
          TextView title = (TextView) tabIndicator.findViewById(R.id.title);
          title.setText(labelId);    

          spec.setIndicator(tabIndicator);
          spec.setContent(intent);
          tabHost.addTab(spec);
    }

05-25 11:18:49.725: E/AndroidRuntime(428): FATAL EXCEPTION: main
05-25 11:18:49.725: E/AndroidRuntime(428): java.lang.IllegalStateException: Could not execute method of the activity
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.view.View$1.onClick(View.java:2072)
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.view.View.performClick(View.java:2408)
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.view.View$PerformClick.run(View.java:8816)
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.os.Handler.handleCallback(Handler.java:587)
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.os.Looper.loop(Looper.java:123)
05-25 11:18:49.725: E/AndroidRuntime(428):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-25 11:18:49.725: E/AndroidRuntime(428):  at java.lang.reflect.Method.invokeNative(Native Method)
05-25 11:18:49.725: E/AndroidRuntime(428):  at java.lang.reflect.Method.invoke(Method.java:521)
05-25 11:18:49.725: E/AndroidRuntime(428):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

并随后...

最佳回答

设置一个标签,我使用 遵循代码,它的工作正常。

TabHost tabHost = getTabHost();

// Tab for Photos
TabSpec photospec = tabHost.newTabSpec("Photos");
// setting Title and Icon for the Tab
photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
Intent photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);

// Tab for Songs
TabSpec songspec = tabHost.newTabSpec("Songs");
songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
Intent songsIntent = new Intent(this, SongsActivity.class);
songspec.setContent(songsIntent);
 // Adding all TabSpec to TabHost
tabHost.addTab(photospec); // Adding photos tab
tabHost.addTab(songspec); // Adding songs tab
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签