2010-08-21 81 views
0
private class Task_xmlparse extends AsyncTask<String, Void, Void> { 
    private final ProgressDialog dialog = new ProgressDialog(BlackSheepimage.this); 
    protected void onPreExecute() { 
     this.dialog.setMessage("Loading..."); 
     this.dialog.setCancelable(false); 
     this.dialog.show(); 
    } 

    @Override 
    protected Void doInBackground(String... params) 
    { 
     try { 

      DomFeedParser dom = new DomFeedParser(url); 
      Log.v("thread"," "+url); 
      List<Message_thbnail> l_obj_tnail = new ArrayList<Message_thbnail>(); 
      List<Message_zoom> l_obj_zoom = new ArrayList<Message_zoom>(); 
      l_obj_tnail = dom.parse_tnail(); 
      l_obj_zoom = dom.parse_zoom(); 
      VAL1 = new String[l_obj_tnail.size()]; 
      VAL2= new String[l_obj_zoom.size()]; 
      //Log.v("bufersize",""+bufferarray.length); 
      //Log.v("val2Length",""+VAL1.length); 
      Iterator<Message_thbnail> it_tnail = l_obj_tnail.iterator(); 
      while (it_tnail.hasNext()) 
      { 
       k++; 
       Log.v("Zoo",""+zo); 
       VAL1[k] = it_tnail.next().toString(); 
       bufferarray[zo]=VAL1[k]; 
       Log.v("Buffer",bufferarray[zo]); 
       zo++; 


      } 
      Log.v("threadbuffsize",""+zo); 
      Iterator<Message_zoom> it_zoom = l_obj_zoom.iterator(); 
      Log.v("zoosize", ""+l_obj_zoom.size()); 
      while (it_zoom.hasNext()) { 
       k1++; 

       Log.v("Zoo1",""+zo1); 
       VAL2[k1] = it_zoom.next().toString(); 
       zoombufferarray[zo1]=VAL2[k1]; 
       zo1++; 
       Log.v("tag",VAL2[k1].toString()); 

      } 

      thumbnail_disp=bufferarray; 
      grid= new GridAdapter(BlackSheepimage.this,bufferarray); 
     } catch (Exception e) { 
      //Log.v("Image", "dom" + e); 
     } 

     return null; 
    } 


protected void onPostExecute(Void result) { 

    lay2_gv.setAdapter(grid); 
    if (this.dialog.isShowing()) { 
     this.dialog.dismiss(); 
    } 
} 

} 
public void onCreate(Bundle savedInstanceState) 
{ 
    url="http://www.theblacksheeponline.com/partypics.php?page="+pageno; 
    super.onCreate(savedInstanceState); 
    lay2_gv = (GridView) findViewById(R.id.jr_lookbook_grid); 
    new Task_xmlparse().execute(url); 
    tv = (TextView) findViewById(R.id.next_pg); 
    tv.setOnClickListener(this) ; 
    lay2_gv.setOnItemClickListener(this); 
} 
public void onClick(View arg0) { 


     pageno++; 
     Log.v("pge",""+pageno); 
     lay2_gv.setVisibility(GridView.GONE); 
     url="http://www.theblacksheeponline.com/partypics.php?page="+pageno; 
     //Log.v("URL",url); 
     new Task_xmlparse().execute(url); 

} 

回答

0

我不認爲在這裏使用Intent是正確的。在我收集它時,您將解析xml以顯示圖像,並且希望在用戶單擊按鈕時能夠添加更多圖像。因此,這裏是你需要做什麼:

在按鈕的onClick方法,你應該開始一個AsyncTask或背景Thread,在其中您在您的網址http請求。

這將讓你的下一個圖像的XML,你分析它,並在你的後臺線程準備圖像。

然後回到你的主線程(在onClick方法實例),你搶這些照片,將它們添加到您的GridView的適配器,並呼籲notifyDataSetChanged()更新您GirdView。這應該可以做到。

+0

,您好我跟着你的概念,但現在我打電話的AsyncTask按鈕點擊網址變更和呼叫的AsyncTask,並通過URL當我點擊按鈕,但沒有反映在GridView的輸出,GridView控件顯示前16個圖像是顯示在GridView的我能做些什麼如何解決這個問題 – sivaraj 2010-08-21 11:29:54

+0

請嘗試在你的句子中使用標點符號,這真的很難理解你。而且,只要您的評論,我無法幫助您,您需要詳細說明。在你的文章中添加一些代碼,你可能會在你的AsyncTask中出錯。 – Sephy 2010-08-21 11:34:20

+0

public void onClick(View arg0){ \t \t \t \t pageno ++; \t \t \t lay2_gv.setVisibility(GridView.GONE); \t \t \t URL = 「http://www.theblacksheeponline.com/partypics.php?page=」 +您做生意; \t \t new Task_xmlparse()。execute(url); \t \t lay2_gv.setVisibility(GridView.VISIBLE); \t \t \t \t \t} 此代碼我用點擊的方法,但我沒有gridgiew獲得更多的圖像.. – sivaraj 2010-08-21 13:15:33