android - 在android中设置选项卡的内容

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

使用 TabHost 和 TabWidget 我在 android 中创建了两个选项卡,第二个选项卡的问题是它必须显示带有图像的 ListView 。 所以我使用了这里给出的想法 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);
.
.

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

最佳答案

通过膨胀布局

充气

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

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

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

spec2.setContent(view);

关于android - 在android中设置选项卡的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14069361/

相关文章:

android - 使用 setContent 时自定义通知崩溃

android - 如何在点击图片后播放 youtube 视频?

java - Android 应用程序不会显示在 Android Studio 模拟器中

android - 在android中点击通知进入我的应用

android - 从凭证存储中删除证书

android - Cordova android 模拟器 "cannot read property ' 替换“未定义”

android - 再次替换根Fragment时,Fragment的ViewPager不显示其内容

java - 如何将值发送到另一个方法

java - 尽管使用 @NonNull 进行注释,但 Room 上使用 @NonNull 作为主键时仍出现 Android 应用程序错误

Android - URI 方案 - 停止打开多个应用程序实例