Balkyto
Balkyto

Reputation: 1510

Can Android Sherlock Tabs hold listview and have single activity for each tab?

I've implemented Sherlock action bar tabs today, so my tab handling class extends SherlockActivity implements ActionBar.TabListener.

I start some empty layout, and then each tab has it's own layout, and it works fine.

First, on my first tab I need a list (but can't extend listview obviously). I'm using Strings and then string array

<string-array name="my_keys">
    <item>@string/mytab_mymonitor</item>
    <item>@string/mytab_mymessaging</item>
    <item>@string/mytab_information</item>
</string-array>

So first, how to populate listview from strings using adapter?

I tried this, but it crashes my app:

myKeys = getResources().getStringArray(R.array.my_keys);
        ListView mListView = (ListView) findViewById(R.id.lvMyList);

        mListView.setAdapter(new ArrayAdapter<String>(this, 
android.R.layout.simple_list_item_1, myKeys));

Second question here is, as I'll have 5 tabs with lot of data processing, is it normal to have everything within "Tab.Listener" activity, or could I somehow use multiple classes / activities while my tabs would still be on place?

Upvotes: 0

Views: 677

Answers (1)

Benito Bertoli
Benito Bertoli

Reputation: 25793

The key is to use Tabs with a ViewPager and Fragments. That way you could put any type of content you need (e.g. you could use a ListFragment).

Check out this code snippet I've written in another answer.

Upvotes: 1

Related Questions