Hi everyone,

The problem is as follows:
- My app is deriving from TabActivity that has 3 tabs
- Each tab has a ListView
- Tab1 is populated by an adapter that inherit SimpleCursorAdapter and
overrided the bindView() method. This tab is displaying correctly.
- Tab 2 is also populated by another adatper that inherit
SimpleCursorAdapter and overrided the bindView() method. For some
reason that I don't understand, the overrided bindView() is not being
called at all. Thus the tab is not displaying correctly.

How come the overrided bindView is not being called? What did I miss?

Here's my code fragment:

MyApp.java
public class MyApp extends TabActivity
{
  private TabHost mTabHost;

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mTabHost = getTabHost();
 
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1").setContent(R.id.TAB1));
 
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab2").setContent(R.id.TAB2));
 
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3").setContent(R.id.TAB3));
    mTabHost.setCurrentTabByTag("tab1");

    ListView view1 = (ListView)findViewById(R.id.TAB1);
    populate(view1);

    ListView view2 = (ListView)findViewById(R.id.TAB2);
    populate2(view2);
  }

  private void populate(ListView view)
  {
    ...
    // some code that fills cursor1
    ...
    adapter1 = new Adapter1(this, R.layout.tab1_entry, cursor1, from1,
to1);
    view.setAdapter(adapter1);
  }

  //
  private void populate2(ListView view)
  {
    ...
    // some code that fills cursor2
    // I have traced in debugger that cursor2, from2, to2 are not null
    ...
    adapter2 = new Adapter2(this, R.layout.tab2_entry, cursor2, from2,
to2);
    view.setAdapter(adapter2);
  }
}


Adapter1.java
public class Adapter1 extends SimpleCursorAdapter
{
  Activity mActivity;

  public Adapter1(Activity activity, int layout, Cursor c, String[]
from, int[] to)
  {
    super(activity, layout, c, from, to);
    mActivity = activity;
  }

  /**
   * {...@inheritdoc}
   */
  @Override
  public void bindView(View view, Context context, Cursor cursor)
  {
    super.bindView(view, context, cursor);
    ...
    // Do custom binding, this is working fine
    ...
  }
}


Adapter2.java
public class Adapter2 extends SimpleCursorAdapter
{

  public Adapter2(Context context, int layout, Cursor c, String[]
from, int[] to)
  {
    super(context, layout, c, from, to);
  }

  /**
   * {...@inheritdoc}
   */
  @Override
  public void bindView(View view, Context context, Cursor cursor)
  {
    ...
    // Do custom binding here
    // But this function is never being called.
    // I put breakpoint here in debugger, the method is not entered
    ...
  }
}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <ListView
                    android:id="@+id/TAB1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="Tab 1" />
                <ListView
                    android:id="@+id/TAB2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="Tab 2" />
                <ListView
                    android:id="@+id/TAB3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="Tab 3" />
            </FrameLayout>
    </LinearLayout>
</TabHost>


tab1_entry.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
    <TextView android:text="@+id/Field11"
              android:id="@+id/Field11"
              android:focusable="false"
              android:clickable="false"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
    <ImageView android:id="@+id/separator1"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:focusable="false"
               android:clickable="false"
               android:layout_alignParentTop="true"
               android:layout_alignParentBottom="true"
               android:layout_marginRight="4px"/>
    <TextView android:text="@+id/Field12"
              android:id="@+id/Field12"
              android:focusable="false"
              android:clickable="false"
              android:phoneNumber="true"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
    <ImageView android:id="@+id/separator2"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:focusable="false"
               android:clickable="false"
               android:layout_alignParentTop="true"
               android:layout_alignParentBottom="true"
               android:layout_marginRight="4px"/>
    <TextView android:text="@+id/Field13"
              android:id="@+id/Field13"
              android:phoneNumber="true"
              android:focusable="false"
              android:clickable="false"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
</LinearLayout>


tab2_entry.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
    <TextView android:text="@+id/Field21"
              android:id="@+id/Field21"
              android:focusable="false"
              android:clickable="false"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
    <ImageView android:id="@+id/separator3"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:focusable="false"
               android:clickable="false"
               android:layout_alignParentTop="true"
               android:layout_alignParentBottom="true"
               android:layout_marginRight="4px"/>
    <TextView android:text="@+id/Field22"
              android:id="@+id/Field22"
              android:focusable="false"
              android:clickable="false"
              android:phoneNumber="true"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
    <ImageView android:id="@+id/separator4"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:focusable="false"
               android:clickable="false"
               android:layout_alignParentTop="true"
               android:layout_alignParentBottom="true"
               android:layout_marginRight="4px"/>
    <TextView android:text="@+id/Field23"
              android:id="@+id/Field23"
              android:phoneNumber="true"
              android:focusable="false"
              android:clickable="false"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
</LinearLayout>

Thanks & Regards,
Seamus Huang

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to