Access Listview from TabActivity

by Kid24 » Wed, 21 Apr 2010 02:30:27 GMT


Sponsored Links
 Hello,

I wonder if anyone can help me to solve my issue. The problem - I
can't find the way to get ListView reference that is the part of
TabActivity.
I have 2 tabs - ListView, TextView. Theare no problem to access
TextView using the following code in TabActivity:

FrameLayout frame = tabHost.getTabContentView();
TextView text = (TextView)
((LinearLayout)frame.getChildAt(1)).getChildAt(0);

But frame.getChildAt(0) returns
com.android.internal.policy.impl.PhoneWindow$DecorView
And I actualy don't know the way how to cast this reference to the
object and to get its ListView child.

Could anybody help me, please?

Tab initialization code:

protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                final TabHost tabHost = getTabHost();

                tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(
                                getString(R.string.tab_auth_list)).setContent(
                                new Intent(this, MainListActivity.class)));

                LayoutInflater.from(this).inflate(R.layout.help,
                                tabHost.getTabContentView(), true);

                tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(
                                
getString(R.string.tab_help)).setContent(R.id.help_txt));
}

--



Access Listview from TabActivity

by Prajakta Shitole » Wed, 21 Apr 2010 05:26:56 GMT


 Hi,

You can have a list Activity and then in you tabActivity just pass that
activity in setcontent. For eg:
In the example below First.class and Second.class are my ListActivities.

public class ExampleTab extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabst);

        TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1")

 .setIndicator("First",getResources().getDrawable(R.drawable.tab1))
                .setContent(new Intent(this, First.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")

 .setIndicator("Second",getResources().getDrawable(R.drawable.second))
                .setContent(new Intent(this, Second.class)));


    }
}


Hope this helps,

Thanks,
Prajakta






>


Sponsored Links


Other Threads

1. Question for SDK developers - behavior of setFeatureInt





Good lord, DO NOT DO THIS.  Do you see what you are doing?  You are using
reflection to get at private information, and then using that information to
rip apart the system's decoration layout.  You WILL break in the future.  I
guarantee it.

Please, for me, slap whoever gave you this code.

And yes, this is how setFeatureInt() works.  It would be nice to have it be
more flexible, but for now you need to set these things up before
setContentView().  If you want a changing title bar, you'll need to set your
own custom title bar view up-front and just manage it all yourself.

Okay now I am going to go cry silently in the corner.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

2. Issue w/ extending MapActivity and eclipse error saying that it is not extended

So I am really confused, this has been going on for a while, usually I
could move my activity decleration around in the manifest and it would
work fine. Now its giving me the same error.

I have an activity called savemaplocation extending MapActivity
public class savemaplocation extends MapActivity
{
...
}

I have this line in my manifest for this particular activity
       <activity class=".savemaplocation"
android:label="SaveMapLocation" android:name=".savemaplocation"
android:screenOrientation="portrait">
       </activity>

it keeps saying as an error next to the line in the
manifest .....savemaplocation does not extend android.app.Activity

I am kind of confused, my other activity that happens to be a
MapActivity has no issues.. Help would really be appreciated.

Chris.
--~--~---------~--~----~------------~-------~--~----~

3. build-essential on Mandriva virtual machine

4. ALSA proble

5. Reading /proc and /sy

6. PV2wayEngine crash

7. why XmlPullParser.getName(); return null (urgent)