Question: So basically a Fragment is placed inside an Activity via a ViewPager and I'm trying to populate a ListView which is inside the Fragment by inflating it from the Parent Activity. However, the items don't get populated and no error is thrown.

> 
> The data should be populated from the activity
> 
> 
> The listview is in the fragment
> 
> 
> 

Here's my code:

**Activity**:

```
public class SearchActivity extends ActionBarActivity {

ListView peopleList;
ArrayList<String> data = new ArrayList<>();

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

        //Inflate the Fragment to a new View Object
        LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View vii = inflator.inflate(R.layout.activity_search_people_tab, null);
        //Initialise the ListView with the Fragment's listview
        peopleList = (ListView) vii.findViewById(R.id.searchpeople_list);

        data.add("1");         
        data.add("2");     

        PopulateResults();
}

private void PopulateResults() {
        //populate the fragment's listview with the data generated by the parent activity
        SearchPeopleResultsAdapter adapter = new SearchPeopleResultsAdapter(SearchActivity.this,data);
        peopleList.setAdapter(adapter);
}

```

I simply want to populate a listview which is in the fragment with the values generated by the parent activity. How do I get this done folks?

**EDIT:**

So basically, the ACTIVITY has an EditText and below that I have a ViewPager with two Fragments. The first Fragment has a ListView. 'On Text changed' I need to populate the ListView with the data. This is for a Search functionality :)

Answer: 
There are a bunch of ways you can achieve the ListView's initialization.

**First**: Initialize it from within your Fragment `onCreateView` as the ListView belongs to the Fragment and it makes sense to let it handle this.

**Second**: Add your data into a `Bundle` and add it to the Fragment using `setArguments()` method from Fragment, then inside the `onCreate()` retrieve the `Bundle` and the data you attached.

**Third**: Save a list of your Fragments, saving them from within the `getItem()` inside your `FragmentPagerAdapter`. And when you need to initialize/update the ListView adapter you can retrieve the `Fragment` and call a method created by you to initialize/update the ListView.

Hope this helps!

Edit:

Let's say you have a `TextView` and on its `TextWatcher#afterTextChanged()` method you do something like:

```
// This adapter should be your custom adapter -- extending FragmentPagerAdapter
YourFragment fragment = (YourFragment) mViewPagerAdapter.getFragment(targetFragmentPostion);
fragment.addNewData(yourNewData);

```

Inside `YourFragment#addNewData(...)` method you could have something like:

```
mListOfData.add(newData);
mListViewAdapter.notifyDataSetChanged();

```

I'm assuming you where successful in initializing your ListView, so this edited content is for updating its content.

Hope this helps you.
I am not sure, what the actual implementation on your side without Fragment code, but the way you described its not going to work, as you are inflating a fragments's view in `onCreate()` of Activity by inflating that view xml but the actual fragment view will be rendered on `onCreateView()` of fragment.

So in your case, you have to pass your adapter data from Activity to Fragment via bundle or any other method and just populate your view inside `onCreateView()` of Fragment.

in simple words, as per your current implementation both views are different so it won't effect or update your Fragment view. The actual Fragment view is created by `onCreateView(`) method only (what you seen on your device screen).