How do you add in ExpandableListView to ParentGroup ImageButton?



  • In order to be addressed, it is necessary to reconcile the records downloaded from the server SQLite The base of the device itself and add/authorize in the absence/acquisition (addition to selected). Already done a method of filling ExpandableListViewbut I don't know how to add ImageButton♪ Code of method

    public void setExpandableListView(ArrayList<Dish> val){
        Map<String, String> map;
        ArrayList<Map<String, String>> groupDataList = new ArrayList<>();
        ArrayList<Dish> values = val;
    
    for (int i = 0; i &lt; values.size(); i++) {
        map = new HashMap&lt;&gt;();
        map.put("dishName", values.get(i).getName());
        groupDataList.add(map);
    }
    String groupFrom[] = new String[] { "dishName" };
    int groupTo[] = new int[] { android.R.id.text1 };
    ArrayList&lt;ArrayList&lt;Map&lt;String, String&gt;&gt;&gt; сhildDataList = new ArrayList&lt;&gt;();
    for (int i = 0; i &lt; values.size(); i++) {
        ArrayList&lt;Map&lt;String, String&gt;&gt; сhildDataItemList = new ArrayList&lt;&gt;();
        map = new HashMap&lt;&gt;();
        map.put("dishRecipe", values.get(i).getRecipe());
        сhildDataItemList.add(map);
        сhildDataList.add(сhildDataItemList);
    }
    
    String childFrom[] = new String[] { "dishRecipe" };
    int childTo[] = new int[] { android.R.id.text1 };
    
    final SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
            this, groupDataList,
            android.R.layout.simple_expandable_list_item_1, groupFrom,
            groupTo, сhildDataList, android.R.layout.simple_list_item_1,
            childFrom, childTo);
    
    final ExpandableListView list = (ExpandableListView) findViewById(R.id.list_recipes);
    list.setAdapter(adapter);
    list.deferNotifyDataSetChanged();
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View itemClicked, int position, long id) {
    
        }
    });
    list.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
    
        }
    
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem + visibleItemCount == currentNumOfDishes){
                String[] query = new String[2];
                query[1] = "get_dishes";
                query[0] = "SELECT * FROM Dishes WHERE _id &gt; " + currentNumOfDishes + " AND _id &lt;= " + neededNumOfDishes;
                new AsyncRequest(Recipes_List.this).execute(query);
                scroll = currentNumOfDishes;
                scrollcount = visibleItemCount;
                currentNumOfDishes = neededNumOfDishes;
                neededNumOfDishes += 20;
            }
        }
    });
    if (scroll &gt; 1){
        list.setSelectedGroup(scroll-scrollcount);
    }
    

    }



  • As layout for the groups, you now use the resources provided by the Android: android.R.id.text1. You need to create your resource layout for groups with the necessary markings (appendix ImageButton, etc.), and the code already refers to it accordingly. Well, it's likely that the same should be done for the elements of a child.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2