In my application i am loading data in a galleryview.If user clicks any item in galleryview i will load data from adapterclass.I kept an activity indicator between this loading and displaying data.But the activity indicator is not dismissing,it is showing continuously.

My activity code:

gal.setOnItemClickListener(new OnItemClickListener() 
       {                                                                                                                                                                                                                                                                                                                    
        @Override
        public void onItemClick (AdapterView<?> parent, View v, int position,
                long id) {
            // TODO Auto-generated method stub  

//           mDialog = new ProgressDialog(NewsPaperNov28MainGalleryActivity.this);
//           mDialog.setMessage("Please wait...");
//           mDialog.setCancelable(false);


             mDialog=  ProgressDialog.show(NewsPaperNov28MainGalleryActivity.this,"Working..", "Please Wait", true,false);           
             context.getInstance().setAppVariable("sectionurl", adapter.sectionurl[position]);
             Thread thread = new Thread();
             thread.start();


//          ListView list=(ListView)findViewById(R.id.list);
//          listadapter = new ListViewwithimageAdapter(this);
//          list.setAdapter(listadapter);        

        }
    });


        list.setOnItemClickListener(new OnItemClickListener() 
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) 
            {

                // TODO Auto-generated method stub
                context.getInstance().setAppVariable("storyurl", listadapter.url[position]);        
                Intent in = new Intent(getApplicationContext(), NewsDescription.class);
                startActivity(in);

            }
        });
    }
    @Override
    public void run() {
        // TODO Auto-generated method stub
//      context.getInstance().setAppVariable("sectionurl", adapter.sectionurl[position]);
        System.out.println("inside run");
        list=(ListView)findViewById(R.id.list);
        listadapter = new ListViewwithimageAdapter(this);
        System.out.println("B4 handle");
        handler.sendEmptyMessage(0);
    }

     private Handler handler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             System.out.println("Inside handler");
                 mDialog.dismiss();
                 list.setAdapter(listadapter);

         }
 };

My ListViewwithimageAdapter class:

public class ListViewwithimageAdapter extends BaseAdapter
{
    private static Context contxt;
    final String URL = "http://xxxxxxx/xml/stories/"+rgd.xml;   
     String[] kickerimage = {};//new String[50];

    ListViewwithimageAdapter(Context conxt)
    {

        this.contxt=conxt;
        getelement();

    }

         public ListViewwithimageAdapter(
            OnItemSelectedListener onItemSelectedListener) 
         {
        // TODO Auto-generated constructor stub
//           this.contxt=conxt;
            getelement();
    }

        public ListViewwithimageAdapter(OnItemClickListener onItemClickListener) {
            // TODO Auto-generated constructor stub
            getelement();
        }


        String[] itemsarray = {};//new String[100];
        String[] url= {};//new String[30];
    public String[] getelement()
    {
//        System.out.println("Insid getelement");
          ArrayList<String> menuItems = new ArrayList<String>();
          TaplistingParser parser = new TaplistingParser();
//        System.out.println("url="+URL);
          String xml= parser.getXmlFromUrl(URL);
          Document doc=parser.getDomElement(xml);        
//        System.out.println("sssss="+doc);
          NodeList nl=doc.getElementsByTagName("article"); 
          kickerimage = new String[nl.getLength()];
          url = new String[nl.getLength()];

//        String headings = null;

          for(int i=0; i < nl.getLength(); i++)
          {

//            System.out.println("i="+i);
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);
//          map.put("Title", parser.getValue(e, "title"));
//          map.put("Date", parser.getValue(e, "create_date"));         
            url[i]=parser.getValue(e, "url");
//          System.out.println("b4 kick");
//          System.out.println("value="+parser.getValue(e, "title"));
            kickerimage[i]=parser.getValue(e, "kickerimage");
//          System.out.println("after kick");
//          System.out.println("kick="+kickerimage[i]);
            menuItems.add(parser.getValue(e, "title"));          
          }  
//         System.out.println("b4 items array");
           itemsarray = new String[menuItems.size()];
//         System.out.println("subbu");
           itemsarray=menuItems.toArray(itemsarray);
//         System.out.println("subbu1");
//         System.out.println("in last");
           return itemsarray;
    }
    @Override
    public int getCount() 
    {
        // TODO Auto-generated method stub
        return itemsarray.length;
    }

    @Override
    public Object getItem(int position) 
    {
        // TODO Auto-generated method stub
        return itemsarray[position];
    }
    @Override
    public long getItemId(int position) 
    {
        // TODO Auto-generated method stub
//      System.out.println("pos in id="+position);
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {



        // TODO Auto-generated method stub      
         Bitmap bitmap = DownloadImage(
                 kickerimage[position] );        
//       View listView = convertView;
         if (convertView   == null) 
            {
                //this should only ever run if you do not get a view back            
             LayoutInflater  inflater = (LayoutInflater) contxt
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             convertView  = inflater.inflate(R.layout.homelistrow, null); 
            }
//       else
//       {
//           holder.removeAllViews();
//       }
//      View listView;
//      if (convertView == null) 
//      {
//          listView = new View(contxt);             
//          LinearLayout holder = (LinearLayout)convertView.findViewById(android.R.id);
////            holder = inflater.inflate(R.layout.homelistrow, null); 
//          System.out.println("pos="+position);
//          System.out.println("item="+getItem(position));
//       else
//       {
            TextView textView = (TextView) convertView
                    .findViewById(R.id.name_label);
            textView.setText(itemsarray[position]);

            ImageView imageView = (ImageView) convertView
                    .findViewById(R.id.icon);
            imageView.setImageBitmap(bitmap);
//      }
//      else        
//      {
//          listView = (View) convertView;
//      } 
//       }

        return convertView ;        
    }   
    private Bitmap DownloadImage(String URL)
    {        
//      System.out.println("image inside="+URL);
        Bitmap bitmap = null;
        InputStream in = null;        
        try {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in);
            in.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
//        System.out.println("image last");
        return bitmap;                
    }
    private InputStream OpenHttpConnection(String urlString)
            throws IOException
            {
                InputStream in = null;
                int response = -1;

                URL url = new URL(urlString);
                URLConnection conn = url.openConnection();

                if (!(conn instanceof HttpURLConnection))                    
                    throw new IOException("Not an HTTP connection");

                try{
                    HttpURLConnection httpConn = (HttpURLConnection) conn;
                    httpConn.setAllowUserInteraction(false);
                    httpConn.setInstanceFollowRedirects(true);
                    httpConn.setRequestMethod("GET");
                    httpConn.connect();

                    response = httpConn.getResponseCode();                
                    if (response == HttpURLConnection.HTTP_OK) 
                    {
                        in = httpConn.getInputStream();                                
                    }                    
                }
                catch (Exception ex)
                {
                    throw new IOException("Error connecting");            
                }
                return in;    
    }
}

Where i am going wrong??Please help me thanks in advance..

有帮助吗?

解决方案

I solved it ..the problem lies in the line

Thread thread = new Thread();

Instead of this i done:

Thread thread = new Thread(Myactivity.this);

Now the Indicator is disappearing after loading.Thanks to all..

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top