【问题标题】:Setting the contents of a tab in android在android中设置选项卡的内容
【发布时间】:2012-12-28 12:09:04
【问题描述】:

使用 TabHost 和 TabWidget 我在 android 中创建了两个选项卡,第二个选项卡的问题是它必须显示带有图像的列表视图。 所以我使用了这里给出的想法http://wptrafficanalyzer.in/blog/listview-with-images-and-text-using-simple-adapter-in-android/

所以我的 tab2 指的是该链接中给出的 mail.xml。如何从 tab2 调用 mainactivity.java 以便显示列表的内容?

.//tab 1 contents
.
TabSpec spec2 = tabHost.newTabSpec("Categories");
spec2.setIndicator("Categories",
getResources().getDrawable(R.drawable.ic_menu_categories));
spec2.setContent(R.id.main);
.
.

在这里,我需要调用使用简单适配器创建该列表视图的类。我怎么做? 请回复

【问题讨论】:

  • 仅供参考 tab2 内容在 xml 中。因此,我将该 tag2 id 命名为 main。所以 R.id.main 是有效的..

标签: android android-layout android-intent android-tabhost


【解决方案1】:

通过膨胀布局

用于充气

不知道你使用的是哪种布局

LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflate.inflate(R.id.main, null);

现在您可以在选项卡中将其设置为 contentView

spec2.setContent(view);

【讨论】:

    【解决方案2】:

    据我了解,您需要在 Tab2 中打开 MainActivity。 为此,您必须执行以下操作:

    TabSpec spec2 = tabHost.newTabSpec("Categories");
    spec2.setIndicator("Categories",
    getResources().getDrawable(R.drawable.ic_menu_categories));
    Intent intent = new Intent( getApplicationContext( ), MainActivity.class );
    spec2.setContent( intent );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-27
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      相关资源
      最近更新 更多