Answer the question
In order to leave comments, you need to log in
Android access content inside TabHost?
Hello. There is an Activity that inherits from TabActivity. There is also an Activity class that is added by the content of the tab. How can I access lvContent from MainActivity class? Thanks in advance! PS I didn't figure out how to format the xml code... sorry.
[xml Activity]
<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"><linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"><tabhost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"><linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"><tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /><framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#AAFF0000" /></linearlayout></tabhost></linearlayout></relativelayout>
<?xml version="1.0" encoding="utf-8"?>
<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"><listview android:id="@+id/lvContent" android:layout_width="match_parent" android:layout_height="match_parent" /></relativelayout>
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);
}
}
Answer the question
In order to leave comments, you need to log in
Try like this:
// Получаем активити из первого таба
Tab1 tabActivity = (Tab1) getTabHost().getChildAt(0).getContext();
// Вызываем стандартный метод findViewById
ListView list = (ListView) tabActivity.findViewById(R.id. lvContent);
And what prevents you from seeing what your postcode means for your BIOS?
How can a speaker help you?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question