我用片段做了两个标签
我想在第一个标签上添加一个可扩展的列表,但我不知道如何,因为我找到的每个示例都显示了如何在活动中实现它。
我想这样做:
答案 0 :(得分:2)
XML:
<?xml version="1.0" encoding="utf-8" ?>
<FrameLayout xmlns ....
android:layout_height="match_parent"
android:layout_width="math_parent" >
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
... />
</FrameLayout>
创建新的片段类
public ExpendListFragment extends Fragment {
private ExpendableListView mList;
public void onCreateView(...... ) {
View root = inflater.inflate(R.layout.xml_layout,container,false);
mList = (ExpendableListView) root.findViewById(R.id.list);
//create and set adapter here.
return root;
}
活动类
私人ViewPager mPager; private FragmentStatePagerAdapter mAdapter;
public void onCreate(... ) {
super(..}
setContentView(...)
mPager = findViewById(R.id.pager);
mAdapter = new FragmentStatePagerAdapter(getSupportFragmentManager());
//In the Adapter create List of Fragments
ExpendListFragment fragment = new ExpendListFragment();
mAdapter.add(fragment);
mPager.setAdapter(mAdapter);
}
希望它有所帮助。