ExpandableListFragment android

时间:2014-07-25 05:34:13

标签: android expandablelistview android-listfragment expandablelistadapter

public class ProfileFragment extends ListFragment
{  
        /** An array of items to display in ArrayList */
        String profile_list[] = new String[]{
            "Personal Info",
            "Account Info"
        };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        /** Creating array adapter to set data in listview */
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, profile_list);

        /** Setting the array adapter to the listview */
        setListAdapter(adapter);

        return super.onCreateView(inflater, container, savedInstanceState);
    }    

    @Override
    public void onStart()
    {     
        super.onStart();
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

    @Override
    public void onListItemClick(ListView l, View v, int pos, long id)
    {
        super.onListItemClick(l, v, pos, id);
        Toast.makeText(getActivity(), "Item " + pos + " was clicked", Toast.LENGTH_SHORT).show();
    }
}

这是我的适配器

public class MyFragmentPagerAdapter extends FragmentPagerAdapter
{
    final int PAGE_COUNT = 2;

    /** Constructor of the class */
    public MyFragmentPagerAdapter(FragmentManager fm)
    {
        super(fm);
    }

    /** This method will be invoked when a page is requested to create */
    @Override
    public Fragment getItem(int arg0)
    {
        Bundle data = new Bundle();
        switch(arg0)
        {
            /** Home tab is selected */
            case 0:
                HomeFragment homeFragment = new HomeFragment(); 

                data.putInt("current_page", arg0+1);
                homeFragment.setArguments(data);
                return homeFragment;

            /** Profile tab is selected */
            case 1:
                ProfileFragment profileFragment = new ProfileFragment();

                data.putInt("current_page", arg0+1);
                profileFragment.setArguments(data);
                return profileFragment; 
        }

        return null;
    }

    /** Returns the number of pages */
    @Override
    public int getCount()
    {       
        return PAGE_COUNT;
    }
}

第二个标签页上有两个项目,即个人信息和帐户信息。我想添加他们的孩子就像当用户点击个人信息列表时将展开并显示他们的子项并在用户再次点击时隐藏。

请告诉我现有代码中变化最小的解决方案。

感谢高级

0 个答案:

没有答案