简体   繁体   中英

Using ListView in Fragments with SlidingTabs

I'm new to Android development. I'm trying to create custom ListView in Fragment that is in Sliding tab and I can't find class that is compatible with everything i need. In one tab I need to have listView so I tried to use Fragment and ListFragment class but in that classes there is no findViewById method, if I used FragmentActivity class in my PagerAdapter class that combines two tabs there is error because it's not compatible.

Where I can find example with sliding tabs that uses fragments with ListView?

You could simply use two fragments in FragmentActivity class. In that class inflate your ViewPager and put your two fragments in that pager. In your ListView Fragment, use layout with listview and simply when you createView for fragment, you have to inflate it with a view. Use view.findViewById method to inflate your ListView.

You should use a Fragment. The answer to why you didn't find findViewById is, because it works a little bit different in Fragments:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_name, container, false);

    ListView listView = (ListView) rootView.findViewById(R.id.listViewId);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM