Well, i'm trying to find a ListView inside a fragment, to be Able to add and remove items through the Main Activity that created it. here is my attempt (i based it on com.viewpagerindicator.sample), but when i try to access the mainListView in the end, it crashes.
public final class ContactListFragment extends Fragment {
private ListView MyListView;
public ListView GetListView()
{
return MyListView;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
LinearLayout theLayout = (LinearLayout) inflater.inflate(R.layout.tab_frag, container, false);
MyListView = (ListView)theLayout.findViewById(R.id.listViewx);
MyListView.setAdapter(adapter);
return theLayout;
}
}
and here it it's layout
<ListView
android:id="@+id/listViewx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
and that's the code of Main Activity that i want to access listview from to be able to modify public class ContactListActivity extends BaseSampleActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs);
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, ContactListFragment.class.getName()));
fragments.add(Fragment.instantiate(this, ContactListFragment.class.getName()));
fragments.add(Fragment.instantiate(this, ContactListFragment.class.getName()));
PagerAdapter mAdapter = new PagerAdapter(getSupportFragmentManager(), fragments);
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
TabPageIndicator mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
ContactListFragment XCLF = (ContactListFragment) fragments.get(1);
ListView mainListView = (ListView) XCLF.GetListView();
}
any help would be appreciated, thanks