更新ScrollView中线性布局的子视图的索引

时间:2014-09-02 06:35:16

标签: android android-custom-view

您好我正在开发一个应用程序,其中我在Scrollview中添加图像并在相同的点击上保留图像URL的arraylist。如果在scrollview中有10个图像,则Arraylist中将有10个URL。现在我在scrollview的每个项目上都有删除按钮,并且想要从arraylist中删除图像和相应的图像URL,但是在删除2-3个图像后我得到了arrayIndexoutofbound异常。这是我的代码:

  convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(image_url.size()<15)
                {
                list.get(position).put("count",String.valueOf(Integer.parseInt(list.get(position).get("count"))+1));

                 image_url.add(imageUrls.get(position));
                 DynamicView(list_views, imageUrls.get(position));
                 count.setText("("+image_url.size()+")");

                }
                else{
                    Toast.makeText(getApplicationContext(), "Max 15 images can be selected.", 89).show();
                }

              notifyDataSetChanged();
            }
        });

  int j;
private void DynamicView(final LinearLayout dynamic, String url){

      LayoutInflater linflater2 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      for( j=0;j<image_url.size();j++);

      {
          final View customView2 = linflater2.inflate(R.layout.view_item,null);

         RelativeLayout image=(RelativeLayout)customView2.findViewById(R.id.rel_image);
         ImageView cross=(ImageView)customView2.findViewById(R.id.cross);

         Bitmap l = decodeSampledBitmapFromUri(url, 200, 200);
            Drawable d = new BitmapDrawable(l);
         image.setBackgroundDrawable(d);
        cross.setId(j);
        customView2.setId(j);
         cross.setOnClickListener(new OnClickListener() {
            // int size=image_url.size();
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub



        System.out.println("id =="+arg0.getId());
            dynamic.removeView(customView2);
            image_url.remove(arg0.getId());
            count.setText("("+image_url.size()+")");
            System.out.println("size 1= =="+image_url.size());
            System.out.println("size  2 =="+dynamic.getChildCount());
            dynamic.getChildAt(arg0.getId());

            }
        });
         dynamic.addView(customView2);
}

有些事情出了问题,请帮我解决这个问题。在此先感谢。

0 个答案:

没有答案