@themr9l

Android доступ к контенту внутри TabHost?

Здравствуйте. Имеется Activity наследуемое от TabActivity. Так же есть Activity класса который добавляется контентом таба. Как мне получить доступ к lvContent из класса MainActivity? Заранее спасибо! P.S. Не разобрался как отформатировать xml код...извините.

[xml Activity]
&lt;relativelayout xmlns:tools="<a href="http://schemas.android.com/tools">http://schemas.android.com/tools</a>" xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>" android:id="@+id/rlRoot" android:layout_width="match_parent" android:layout_height="match_parent"&gt;&lt;linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt;&lt;tabhost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"&gt;&lt;linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt;&lt;tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /&gt;&lt;framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#AAFF0000" /&gt;&lt;/linearlayout&gt;&lt;/tabhost&gt;&lt;/linearlayout&gt;&lt;/relativelayout&gt;

[xml контента таба]
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;relativelayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>" android:id="@+id/rlTest" android:layout_width="match_parent" android:layout_height="match_parent"&gt;&lt;listview android:id="@+id/lvContent" android:layout_width="match_parent" android:layout_height="match_parent" /&gt;&lt;/relativelayout&gt;


[Код инициализации:]
public class MainActivity extends TabActivity {

	public static ListView currentListView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		final TabHost tabHost = getTabHost();
		
		TabHost.TabSpec tabSpec = tabHost.newTabSpec("tag1");
		tabSpec.setContent(new Intent().setClass(this, Tab1.class));
		tabSpec.setIndicator("TAB 1");
		tabHost.addTab(tabSpec);

		tabSpec = tabHost.newTabSpec("tag2");
		tabSpec.setContent(new Intent().setClass(this, Tab1.class));
		tabSpec.setIndicator("TAB 2");
		tabHost.addTab(tabSpec);
		
		tabHost.setCurrentTab(0);
	}
}
  • Вопрос задан
  • 3512 просмотров
Пригласить эксперта
Ответы на вопрос 1
vasart
@vasart

Попробуй так:

// Получаем активити из первого таба
Tab1 tabActivity = (Tab1) getTabHost().getChildAt(0).getContext();
// Вызываем стандартный метод findViewById
ListView list = (ListView) tabActivity.findViewById(R.id. lvContent);

Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы