title: how to create a list view using action bar tabs with fragment?
body: <p>i am creating a simple app that allow user to login then display the action bar that contain three tabs that each one of it contains a list using list view .</p>
  
  <p>the problem is that i do not know how to build a list view inside fragments can anyone help me ?????</p>
  
  <h1>AndroidNavigationTabsActivity</h1>
  
  <pre><code>package com.exercise.AndroidNavigationTabs;
  
  import android.app.ActionBar;
  import android.app.ActionBar.Tab;
  import android.app.Activity;
  import android.app.Fragment;
  import android.app.FragmentTransaction;
  import android.os.Bundle;
  
  public class AndroidNavigationTabsActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          final ActionBar actionBar = getActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          Tab tabA = actionBar.newTab();
          tabA.setText("Tab A");
          tabA.setTabListener(new TabListener&lt;MyFragmentA&gt;(this, "Tag A", MyFragmentA.class));
          actionBar.addTab(tabA);
  
          Tab tabB = actionBar.newTab();
          tabB.setText("Tab B");
          tabB.setTabListener(new TabListener&lt;MyFragmentB&gt;(this, "Tag B", MyFragmentB.class));
          actionBar.addTab(tabB);
  
          Tab tabC = actionBar.newTab();
          tabC.setText("Tab C");
          tabC.setTabListener(new TabListener&lt;MyFragmentC&gt;(this, "Tag C", MyFragmentC.class));
          actionBar.addTab(tabC);
  
          if (savedInstanceState != null) {
              int savedIndex = savedInstanceState.getInt("SAVED_INDEX");
              getActionBar().setSelectedNavigationItem(savedIndex);
          }
  
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          // TODO Auto-generated method stub
          super.onSaveInstanceState(outState);
          outState.putInt("SAVED_INDEX", getActionBar().getSelectedNavigationIndex());
      }
  
      public static class TabListener&lt;T extends Fragment&gt; 
          implements ActionBar.TabListener{
  
          private final Activity myActivity;
          private final String myTag;
          private final Class&lt;T&gt; myClass;
  
          public TabListener(Activity activity, String tag, Class&lt;T&gt; cls) {
              myActivity = activity;
              myTag = tag;
              myClass = cls;
          }
  
          @Override
          public void onTabSelected(Tab tab, FragmentTransaction ft) {
  
              Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
  
              // Check if the fragment is already initialized
              if (myFragment == null) {
                  // If not, instantiate and add it to the activity
                  myFragment = Fragment.instantiate(myActivity, myClass.getName());
                  ft.add(android.R.id.content, myFragment, myTag);
              } else {
                  // If it exists, simply attach it in order to show it
                  ft.attach(myFragment);
              }
  
          }
  
          @Override
          public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  
              Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
  
              if (myFragment != null) {
                  // Detach the fragment, because another one is being attached
                  ft.detach(myFragment);
              }
  
          }
  
          @Override
          public void onTabReselected(Tab tab, FragmentTransaction ft) {
              // TODO Auto-generated method stub
  
          }
  
      }
  }
  </code></pre>
  
  <p><strong>i get a problem with the tabA after i changed the  MyfragmentA that was extending Fragment to become extanding Activity</strong></p>
  
  <h1>MyFragmentA</h1>
  
  <pre><code>package com.exercise.AndroidNavigationTabs;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.Toast;
  
  public class MyFragmentA extends Activity implements OnItemClickListener {
  
      ListView dalil_khadamet_list;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.fragment_a);
          dalil_khadamet_list = (ListView) findViewById(R.id.khadamet_list);
  
          String[] values = new String[] { "وظائف", "عقارات", "سيارات", "تجارة",
                  "ثقافة" };
  
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_list_item_1, android.R.id.text1, values);
  
          dalil_khadamet_list.setAdapter(adapter);
  
          dalil_khadamet_list.setOnItemClickListener(this);
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt;  parent, View view,
              int position, long id) {
          // TODO Auto-generated method stub
  
            // ListView Clicked item index
          int itemPosition= position;
  
          // ListView Clicked item value
          String  itemValue = (String) dalil_khadamet_list.getItemAtPosition(position);
  
           // Show Alert 
           Toast.makeText(getApplicationContext(),
             "Position :"+itemPosition+"  ListItem : " +itemValue , Toast.LENGTH_LONG)
             .show();
  
  
      }
  
      /*
       * @Override public View onCreateView(LayoutInflater inflater, ViewGroup
       * container, Bundle savedInstanceState) { View myFragmentView =
       * inflater.inflate(R.layout.fragment_a, container, false); return
       * myFragmentView; }
       */
  
  }
  </code></pre>
  
  <h1>fragment_a.xml</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" &gt;
     &lt;TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="It's Fragment A" /&gt;
  
     &lt;ListView
         android:id="@+id/khadamet_list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" &gt;
     &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>