Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中为每个expnadle列表组设置图标图像_Android - Fatal编程技术网

如何在android中为每个expnadle列表组设置图标图像

如何在android中为每个expnadle列表组设置图标图像,android,Android,我正在使用一个可扩展列表适配器来放置视图,它有3个组,每个组有4个子组,目前每个组都有相同的图标图像。 我需要把3张不同的图片放在这三组。。如何在安卓系统中实现这一点。。 请帮忙 我认为您已经在一个类中扩展了BaseExpandableListAdapter。因为你将有一种方法 public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup pa

我正在使用一个可扩展列表适配器来放置视图,它有3个组,每个组有4个子组,目前每个组都有相同的图标图像。 我需要把3张不同的图片放在这三组。。如何在安卓系统中实现这一点。。
请帮忙

我认为您已经在一个类中扩展了BaseExpandableListAdapter。因为你将有一种方法

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            View row = convertView;
            MyHolder hldr = null;
            try{
                if(row==null){
                    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    row = inflater.inflate(R.layout.disp_lib_group_row, null);
                    hldr = new MyHolder();
                    hldr.txtv1 = (TextView) row.findViewById(R.id.txtGrp);
                    hldr.imgv1 = (ImageView) row.findViewById(R.id.imgGrp);
                    row.setTag(hldr);
                }
                else{
                    hldr=(MyHolder)row.getTag();
                }
                hldr.txtv1.setText(getGroup(groupPosition).toString());


          EDIT    EDIT    EDIT    EDIT    EDIT
                   System.out.println("Group Position: "+groupPosition);
                   //    here you will get groupPosition, like 0/1/2/3
                   //    just check it by if condition and
                   //    set needed image in followin line code
                   if(groupPosition == 0)
                    hldr.imgv1.setImageResource(R.drawable.img0);
                   if(groupPosition == 1)
                    hldr.imgv1.setImageResource(R.drawable.img1);
                   ......  Check 2, 3 ......
          EDIT    OVER    OVER


                }
            }catch(Exception e){System.out.println("Error: \n");e.printStackTrace();}
            return row;
        }

是的,我在我的类中使用ExpandableListAdapter,从上图可以看出,它仅在其展开时更改图标。在我的应用程序中,当组显示在视图中时,我需要将三个不同的图形放在三个不同的组中。。例如,假设我有三个组名1.Travel 2.price 3.extra,那么当我在视图上显示三个组名时,这三个组名应该有三个不同的图像。您好,这段代码对我帮助很大,我很困惑创建一个xml文件来保存所有图像。。我是否需要创建一个包含所有图像项的选择器,并将此xml包含在main.xml..中。。?