简体   繁体   English

如何在ExpandableListView中单击父项时加载子项

[英]How to load child items while click parent item in ExpandableListView

I am new for android, I have an ExpandableListView in my app. 我是Android新手,我的应用程序中有一个ExpandableListView。 I want to load child items only while click parent Item. 我只想在单击父项时加载子项。 I tried alot but its not working . 我尝试了很多,但是没有用。 Please anyone help. 请任何人帮助。

My code here: 我的代码在这里:

ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.faq, container, false);
    // get the listview
    expListView = (ExpandableListView) view.findViewById(R.id.faqList);
    prepareListData();
    listAdapter = new ExpandableListAdapter(getActivity(),listDataHeader,listDataChild);
    // setting list adapter
    expListView.setAdapter(listAdapter);

    // Listview Group expanded listener
    expListView.setOnGroupExpandListener(this);
    return view;
}

private void prepareData(String s) {
    Log.d("Working:","yes");

    listDataChild = new HashMap<String, List<String>>();
   // Adding child data
    List<String> top250 = new ArrayList<String>();
    if(s.equals("Top 250")){
        top250 = new ArrayList<String>();
        top250.add("The Shawshank Redemption Godfather");
    }else if(s.equals("Now Showing")){
        top250 = new ArrayList<String>();
        top250.add("The Conjuring welcome to your world of India");
    }else if(s.equals("Coming Soon..")){
        top250 = new ArrayList<String>();
        top250.add("2 Guns of Indias");
    }else {
        top250 = new ArrayList<String>();
        top250.add("Nothing");
    }
    listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
    listDataChild.put(listDataHeader.get(1), top250);
    listDataChild.put(listDataHeader.get(2), top250);
}

private void prepareListData() {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();

    // Adding child data
    listDataHeader.add("Top 250");
    listDataHeader.add("Now Showing");
    listDataHeader.add("Coming Soon..");

    // Adding child data
    List<String> top250 = new ArrayList<String>();
    top250.add("The Shawshank Redemption");
    top250.add("The Godfather");
    top250.add("The Godfather: Part II");
    top250.add("Pulp Fiction");
    top250.add("The Good, the Bad and the Ugly");
    top250.add("The Dark Knight");
    top250.add("12 Angry Men");

    List<String> nowShowing = new ArrayList<String>();
    nowShowing.add("The Conjuring");
    nowShowing.add("Despicable Me 2");
    nowShowing.add("Turbo");
    nowShowing.add("Grown Ups 2");
    nowShowing.add("Red 2");
    nowShowing.add("The Wolverine");

    List<String> comingSoon = new ArrayList<String>();
    comingSoon.add("2 Guns");
    comingSoon.add("The Smurfs 2");
    comingSoon.add("The Spectacular Now");
    comingSoon.add("The Canyons");
    comingSoon.add("Europa Report");

    listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
    listDataChild.put(listDataHeader.get(1), nowShowing);
    listDataChild.put(listDataHeader.get(2), comingSoon);
}

@Override
public void onGroupExpand(int groupPosition) {

    prepareData(listDataHeader.get(groupPosition));
    listAdapter = new ExpandableListAdapter(getActivity(),listDataHeader,listDataChild);
    listAdapter.notifyDataSetChanged();
    // setting list adapter
    expListView.setAdapter(listAdapter);
    Toast.makeText(getActivity().getApplicationContext(),listDataHeader.get(groupPosition) + " Expanded",
            Toast.LENGTH_SHORT).show();

}

Thanks in advance! 提前致谢!

Have a look this URL 看看这个URL

URL 网址

This may be help full for you 这可能对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用父级和子级列表中的3个TextViews制作ExpandableListView? - How to make an ExpandableListView with 3 TextViews in parent and child lists? 如何在Android中的Expandablelistview中处理子点击事件? - How to handle child click event in Expandablelistview in Android? ExpandableListView中的静态子项 - Static child item in ExpandableListView ExpandableListView 中的 onClick 子项 - onClick child item in ExpandableListView 如何选中/取消选中 ExpandableListView 中的 CheckedTextView(子项)项? - How to check/uncheck CheckedTextView (child items) items inside ExpandableListView? 在Android的可扩展列表视图中单击父级列表项时加载子项 - Load Child Item when click on Parent List Item in Expandable List view in android 如何在不依赖于父组的情况下在ExpandableListView中获取所有子ID - how to get all the child id in an ExpandableListView without depending on the parent group 如何在ExpandableListView中删除父级和子级之间的特定空间 - How to remove specific space between parent and child in an ExpandableListView 如何使用 ContextMenuItemSelected 长按从 ExpandableListView 中删除项目? - How to delete an item from ExpandableListView on long click with a ContextMenuItemSelected? 父级RecyclerView单击事件的子级RecyclerView项 - Items of Child RecyclerView of parent RecyclerView click event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM