T
T
themr9l2013-11-14 18:08:08
Android
themr9l, 2013-11-14 18:08:08

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]

&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 content tab]
&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;

[initialization code:]
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

2 answer(s)
V
vasart, 2013-11-16
@vasart

Try like this:

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

P
Puma Thailand, 2014-11-22
@opium

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 question

Ask a Question

731 491 924 answers to any question