กล่องโต้ตอบความคืบหน้าไม่แสดง

ฉันมีเครื่องปั่นด้ายสองคน คนหนึ่งชื่ออาหาร และอีกพื้นที่หนึ่ง ฉันกำลังเรียก Thetask().execute ใหม่เมื่อโหลดกิจกรรมโดยมี "init" เป็นอาร์กิวเมนต์ และควรตั้งค่าสปินเนอร์จากบริการเว็บพร้อมกับอาหารที่มีอยู่และรายการพื้นที่ (วิธีการที่ไม่ได้รวมอยู่ที่นี่) และในตอนแรกนักปั่นจะเลือก "ทั้งหมด" ดังนั้น listview"รายการร้านอาหาร" ควรมีร้านอาหารทั้งหมด และเมื่อผู้ใช้เปลี่ยนอาหารหรือพื้นที่จากการหมุน รายการร้านอาหารควรได้รับการอัปเดตพร้อมกับแสดงกล่องโต้ตอบความคืบหน้า ตอนนี้ปัญหาของฉันคือรหัสทั้งหมดใช้งานได้ แต่กล่องโต้ตอบความคืบหน้าเริ่มแสดงขึ้นหลังจากเติม listview และกล่องโต้ตอบความคืบหน้าจะไม่หยุดจนกว่าจะกดปุ่มย้อนกลับ วิธีแก้ไขใด ๆ สำหรับสิ่งนี้จะเป็นความช่วยเหลือ gr8 ขอบคุณล่วงหน้า.

Thetask คลาสสาธารณะขยาย AsyncTask {

     String flagdopost="",x,y;       
     @Override 
     public void onPreExecute() 
     {   
        pg =new ProgressDialog(Restaurantlistdisplay.this);
        pg.setMessage("fetching info....");
        pg.setIndeterminate(true);
        pg.setCancelable(true);
        Log.i("inside preexecute","in pre execute");
        pg.show();

     }   

     public Void doInBackground(String... params)
     {          
        if(params[0].equalsIgnoreCase("init"))
        {
            tempcuisinenamelist = getCuisines();    
            tempcuisinenamelist.add(0,"All");

            tempareanamelist=getAreanames(cid, sid, cityid);
            tempareanamelist.add(0,"All");

            flagdopost="init";  
            Log.i("inside doinbackground 1st",flagdopost);
        }

        else if(params[0].equalsIgnoreCase(""))
        {
            firequery();
            flagdopost="itemselected";
            Log.i("inside doinbackground 2nd",flagdopost);
        }
        else if(params[0].equalsIgnoreCase("itemclick"))
        {
            //sendid=getRestaurantId(params[1],params[2]);  
            x=params[1];
            y=params[2];
            Log.i("in do in backgroung idforbundle is", Integer.toString(sendid));
            flagdopost="itemclicked";
        }
        return null;                     
     } 

    public void onPostExecute(Void result)
     {       
        if(flagdopost.equalsIgnoreCase("init"))
        {
            ArrayAdapter<String> adaptercuisine=new                           ArrayAdapter<String> (Restaurantlistdisplay.this,android.R.layout.simple_spinner_item,tempcuisinenamelist);
            adaptercuisine.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

            ArrayAdapter<String> adapterarea=new ArrayAdapter<String>(Restaurantlistdisplay.this,android.R.layout.simple_spinner_item,tempareanamelist);
            adapterarea.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

            area.setAdapter(adapterarea); 
            area.setSelection(0);
            area.setOnItemSelectedListener(Restaurantlistdisplay.this);
            cuisine.setAdapter(adaptercuisine); 
            cuisine.setSelection(0);
            cuisine.setOnItemSelectedListener(Restaurantlistdisplay.this);

        }
        else if(flagdopost.equalsIgnoreCase("itemselected"))
        {
            getResult(str);
            customlist.clear();
            populateReslist();
            //Log.i("inside 1st firequery","list populated"+customlist.toString());

            restaurant.invalidateViews();
            restaurant.setAdapter(new SimpleAdapter(Restaurantlistdisplay.this,customlist,R.layout.customlistrow,new String[] {"Restaurant Name","Area Name"},
                    new int[] {R.id.tvresname,R.id.tvareaname})
                    {
                   @Override      
                   public View getView(int position, View convertView,ViewGroup parent)
                   {           
                       View view =super.getView(position, convertView, parent); 
                       return view;       
                   }  
                 });

         }
        else if(flagdopost.equalsIgnoreCase("itemclicked"))
        {               
            sendid=getRestaurantId(x,y);
            Bundle bundle=new Bundle();
            bundle.putInt("locid",sendid);
            Toast.makeText(getBaseContext(), "locId in dopost new one"+sendid, 10).show();

            Intent resdetail = new Intent(Restaurantlistdisplay.this,Restaurantdetail.class);
            resdetail.putExtras(bundle);
            startActivity(resdetail);

        }   
         pg.dismiss();
     }  
 }

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) 
{
    switch(arg0.getId())
    {
        case R.id.spncuisine:                                           asynctaskflag="";
                if(cuisine.getSelectedItem().toString()!="All")
                                {
                            cuisineval=cuisine.getSelectedItem().toString();
                        }
                else
                {
                    cuisineval="*";
                }
                new Thetask().execute(asynctaskflag,null,null);
                break;

        case R.id.spnarea:                  
                asynctaskflag="";
                if(area.getSelectedItem().toString()!="All")
                {
                    areaval=area.getSelectedItem().toString();
                }
                else
                {
                    areaval="*";
                }
                new Thetask().execute(asynctaskflag,null,null);
                break;
    }   

}
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}
}

//โค้ดของ getCuisines() อยู่ด้านล่างตามที่ทุกท่านร้องขอ C ถ้ามันสามารถช่วยได้

public List<String> getCuisines()
 {
        String list = null;
        cuisinelist=new ArrayList<String>();
    try
    {
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
       request.addProperty("str", //here goes query to fetch data from table of </br>cuisines);   
       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);      
    HttpTransportSE aht = new HttpTransportSE(URL);     
    aht.debug = true;
    aht.call(SOAP_ACTION, envelope);
    SoapPrimitive results = (SoapPrimitive)envelope.getResponse();
        list=results.toString();
      }
      catch (SocketException ex)
      {  
    ex.printStackTrace();
      }
     catch (Exception e)
     {         
    e.printStackTrace(); 
      } 
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try
{
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document dom = builder.parse(new InputSource(new StringReader(list))); 
    Element root = dom.getDocumentElement();
    NodeList items = root.getElementsByTagName("row");
    for (int i=0;i<items.getLength();i++)
    {
       Node item = items.item(i);
       NodeList properties = item.getChildNodes();
       for (int j=0;j<properties.getLength();j++)
       {
            Node property = properties.item(j);
        String name = property.getNodeName();
        if (name.equalsIgnoreCase("typeName"))
        {
                   cuisinelist.add(property.getFirstChild().getNodeValue());
        }                       
        }
    }
    return cuisinelist;         
  }
  catch (Exception e) 
  {
    throw new RuntimeException(e);
      } 

}


person samir    schedule 02.02.2012    source แหล่งที่มา
comment
กรุณาใส่รหัสไปรษณีย์สำหรับ getCuisines()   -  person Akram    schedule 02.02.2012
comment
@Akki โพสต์รหัสสำหรับ getcuisines ได้โปรดลองดูสิ แต่เพื่อน ฉันคิดว่าเมื่อการควบคุมไปที่รายการที่เลือกของสปินเนอร์ทันทีหลังจากสปินเนอร์ของอาหารประชากร Task().execute() ใหม่จะถูกเรียกใช้อีกครั้ง ดังนั้นอาจต้องโหลดกล่องโต้ตอบความคืบหน้าอีกครั้ง   -  person samir    schedule 03.02.2012


คำตอบ (1)


ลองสิ่งนี้ใน postexecute

 if(pg.isShowing())
{
pg.dismiss();
}

และ getCuisines(); คืออะไร? คุณมี ProgressDialog ตรงนั้นไหม?

หากมันเป็นกิจกรรมที่ซ้อนกันให้ลอง

  ProgressDialog dialogGoog = new ProgressDialog(getParent());
person Shahzad Imam    schedule 02.02.2012
comment
ขอบคุณสำหรับข้อเสนอแนะ จะดำเนินการในวันจันทร์เพราะไม่สามารถเขียนโค้ดที่บ้านได้ บริษัทไม่อนุญาตให้ทำเช่นนั้น getcuisines เป็นวิธีการรับรายการอาหารของร้านอาหาร มันใช้บริการเว็บเซอร์วิส ksoap mthod เพื่อรับรายละเอียดและส่งกลับรายการอาร์เรย์ของอาหารเช่นคอนติเนนตัล อิตาลี จีน ฯลฯ และปัญหาที่คุณสามารถทำได้คือฉันเติมอะแดปเตอร์และตั้งค่าอะแดปเตอร์ ดังนั้นตัวควบคุมอาจข้ามไปที่เหตุการณ์ onItemselected ทันที เครื่องปั่นด้าย และตรรกะ if pg.isshowing ที่คุณแนะนำอาจไม่ทำงาน แต่ให้ฉันลองดูก่อน ขอบคุณ - person samir; 03.02.2012
comment
พยายามแล้วเพื่อนยังคงได้รับผลลัพธ์แบบเดียวกัน กล่องโต้ตอบความคืบหน้ามาหลังจากมุมมองรายการเติมข้อมูล ข้อเสนอแนะเพิ่มเติมใด ๆ จะช่วยได้ .. - person samir; 07.02.2012