title: Add data to a listview on fragment
body: <p>I have an fragment on activity, with an listview element on it. Can't add data to listview. Can someone tell me what is wrong?</p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
  
      public String[] listS ={"item1","item2","item3"};
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main); 
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction ft = fm.beginTransaction();
          MainFragment f = new MainFragment();
          ft.replace(R.id.fragcontainer, f);
          ft.commit();    
          //here the problem occurs
          ListView lv = (ListView)findViewById(R.id.listf);
          lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_row,R.id.labeld, listS));
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>Fragment's class:</p>
  
  <pre><code>public class MainFragment extends Fragment {
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sis){
          return inflater.inflate(R.layout.fragment_layout, container, false);
      }
  
  }
  </code></pre>