0

我正在使用ExpandableListview从服务器加载动态数据。

每个Group Header都有不同的Child Layout

单击Group HeaderChild view服务器加载数据。我正在显示从服务器检索到的图像,但它没有按预期工作

并非所有图像都显示在Child view

@Override
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        _childText = (String) getChild(groupPosition, childPosition);                           
        if (convertView == null) {

            viewHolder=new ViewHolder();


            if(("Shape").equals(_listDataHeader.get(groupPosition))){               
                convertView = infalInflater.inflate(R.layout.list_child_shape, null);
                viewHolder.txtTitle = (TextView) convertView.findViewById(R.id.list_child_chkbox);
                viewHolder.img_shape_icon=(ImageView)convertView.findViewById(R.id.img_shape);
                viewHolder.img_shape_icon.setVisibility(View.VISIBLE);


                new PerformBackgroungTask().execute();

            }
            else{
                //viewHolder.img_shape_icon.setVisibility(View.GONE);
                if (("Clarity").equals(_listDataHeader.get(groupPosition))) {
                    convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                    viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                    viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                    ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.clarity_list);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                    viewHolder.clarity_from.setAdapter(adapter);
                    viewHolder.clarity_to.setAdapter(adapter);


                }
                else if (("Color").equals(_listDataHeader.get(groupPosition))) {
                    convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                    viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                    viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                    ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.color_list);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                    viewHolder.clarity_from.setAdapter(adapter);
                    viewHolder.clarity_to.setAdapter(adapter);                                      
                }                             
            }                     
        }       
        //new PerformBackgroungTask().execute();
        return convertView;
    }

后台任务

class PerformBackgroungTask extends AsyncTask<Void, Void, Void>{

        ProgressDialog progressDialog=new ProgressDialog(_context);
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            //requestWindowFeature(Window.FEATURE_NO_TITLE);            
            progressDialog.setMessage("Please wait...");
            progressDialog.setIndeterminate(true);
            progressDialog.show();
        }       
        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
            try{

                   URL url = new URL("http://rosycontact.com/shashvat/images/"+_childText+".png");
                   bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());                                

               }
                catch (Exception e) {
                    e.printStackTrace();
                }                   
            return null;
        }               
        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            viewHolder.txtTitle.setText(_childText);    
               viewHolder.img_shape_icon.setImageBitmap(bmp);
            if (progressDialog!=null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }       
    }

获取子视图代码...

@Override
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        _childText = (String) getChild(groupPosition, childPosition);     

        int viewIndex=childPosition;  
        ViewHolder viewHolder;
        switch (viewIndex) {

        case 0:
            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder();
                viewHolder=new ViewHolder(); 
                convertView = infalInflater.inflate(R.layout.list_child_shape, null);
                viewHolder.txtTitle = (TextView) convertView.findViewById(R.id.list_child_chkbox);
                viewHolder.img_shape_icon=(ImageView)convertView.findViewById(R.id.img_shape);
                viewHolder.img_shape_icon.setVisibility(View.VISIBLE);                             

                imageLoader.DisplayImage("http://rosycontact.com/shashvat/images/"+_childText+".png", viewHolder.img_shape_icon);
                convertView.setTag(viewHolder);
                //new PerformBackgroungTask().execute();
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        case 1:

            viewHolder = null;
            if (convertView==null) {
                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.clarity_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter);
                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        case 2:

            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder(); 

                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.color_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter);

                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        case 3:

            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder(); 

                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.polish_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter);

                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;
        case 4:

            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder(); 

                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.cut_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter);

                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        case 5:

            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder(); 

                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.symmetry_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter);

                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        case 6:

            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder(); 

                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.florescence_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter);

                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        case 7:

            viewHolder = null;
            if (convertView==null) {
                viewHolder=new ViewHolder(); 

                convertView = infalInflater.inflate(R.layout.list_child_clarity, null);
                viewHolder.clarity_from = (Spinner) convertView.findViewById(R.id.spn_clarity_from);
                viewHolder.clarity_to = (Spinner) convertView.findViewById(R.id.spn_clarity_to);


                ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.certificate_list);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);               
                viewHolder.clarity_from.setAdapter(adapter);
                viewHolder.clarity_to.setAdapter(adapter); 

                convertView.setTag(viewHolder);
            }
            else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            return convertView;

        default:
            break;
        }


     /*// Changing textcolor
        viewHolder.clarity_from.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub

                    String item = (String) parent.getItemAtPosition(position);
                       ((TextView) parent.getChildAt(0)).setTextColor(Color.parseColor("#003974"));                         
                }
                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    // TODO Auto-generated method stub                          
                }
            });
        viewHolder.clarity_to.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto-generated method stub

                String item = (String) parent.getItemAtPosition(position);
                   ((TextView) parent.getChildAt(0)).setTextColor(Color.parseColor("#003974"));                         
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub                          
            }
        });  */ 













        //new PerformBackgroungTask().execute();
        return null;
    }
4

0 回答 0