ActionBar Tabs with list fragments
<p>I've been trying hard to make an ActionBar Tabs. Each Tab should display a list from an ArrayList using setListAdapter.</p>

<p>Up until now, I can't get it right. Please help. </p>

<p>This is my main class: MainActivity.java</p>

<pre><code>    public class MainActivity extends SherlockFragmentActivity {
    ActionBar actionBar;
    /** Called when the activity is first created. */
    @Override`enter code here`
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Tabs
    setContentView(R.layout.main_activity);

    actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab dispatchTab = actionBar.newTab().setText("DISPATCH");
    ActionBar.Tab messagesTab = actionBar.newTab().setText("MESSAGES");
    ActionBar.Tab mapsTab = actionBar.newTab().setText("MAPS");
    dispatchTab.setTabListener(new MyTabListener());
    messagesTab.setTabListener(new MyTabListener());
    mapsTab.setTabListener(new MyTabListener());

    actionBar.addTab(dispatchTab);
    actionBar.addTab(messagesTab);
    actionBar.addTab(mapsTab);

}

private class MyTabListener implements ActionBar.TabListener
{

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        switch(tab.getPosition())
        {
        case 0:
            Toast.makeText(MainActivity.this, "Dispatch Tab", Toast.LENGTH_SHORT).show();

            Fragment fragDispatch = new FragmentDispatch();
            ft.replace(android.R.id.content, fragDispatch);
            break;
        case 1:
            Toast.makeText(MainActivity.this, "Messages Tab", Toast.LENGTH_SHORT).show();

            Fragment fragMessages= new FragmentMessages();
            ft.replace(android.R.id.content, fragMessages);
            break;
        case 2:
            Toast.makeText(MainActivity.this, "Maps Tab", Toast.LENGTH_SHORT).show();
            break;
        }

    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu){
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.main_screen_menu, menu);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId())
    {
        case R.id.compose_image:
            Toast.makeText(this, "Compose Image", Toast.LENGTH_SHORT).show();
            break;

        case R.id.compose_voice:
            Toast.makeText(this, "Compose Voice", Toast.LENGTH_SHORT).show();
            break;

        case R.id.compose_message:
            Toast.makeText(this, "Compose Message", Toast.LENGTH_SHORT).show();
            break;

        case R.id.refresh:
            Toast.makeText(this, "Refresh", Toast.LENGTH_SHORT).show();
            break;
    }
    return super.onOptionsItemSelected(item);
}
</code></pre>

<p>Here is my FragmentMessages that extends SherlockListFragment:</p>

<pre><code>public View onCreateView (LayoutInflater inflater, ViewGroup group, Bundle saved){
    View view = inflater.inflate(R.layout.samplelistview, group, false);

    try {
        synchronized (lock) {
            myData = new ArrayList&lt;HashMap&lt;String, MessageRecord&gt;&gt;();
            Context context = getActivity().getApplicationContext();
            mySimpleAdapter = new MySimpleAdapter(context, myData, R.layout.menurow, mStrings, new int [] {R.id.ivDirection, R.id.tvMessage});
            setListAdapter(mySimpleAdapter);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    return view;
}

@Override
public void onActivityCreated (Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);
    /Pbutton = (Button) getActivity().findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getActivity(), "You have clicked messages button.", Toast.LENGTH_SHORT).show();
        }
    });*/


}
</code></pre>

<p>What I wanted to have is this FragmentMessages returns the data from the ListAdapter. </p>

<p>I badly need your help guys. </p>

<p>Thank you very much.</p>
