2011-08-09 15 views
0

ビュー(子供との相対レイアウト)を追加したいViewFlipperがあります。私はAsyncTaskでこれをしようとしています。ここで ViewFlipperでのビューの追加の追加

は、私が使用していますコードです:保護された無効onProgressUpdateで

class LoadData extends AsyncTask<Object, Void, String> 
{ 
    RelativeLayout rl_main; 

    @Override 
    protected void onPreExecute() 
    { 
     super.onPreExecute();   
    } 

    @Override 
    protected String doInBackground(Object... parametros) 
    { 
     Cursor cur_channel = db_Helper.sqlDB.query(DatabaseHelper.Channels_TableName, null, null, null, null, null, null); 
     startManagingCursor(cur_channel); 

     int index = 0; 
     while(cur_channel.moveToNext()) 
     { 

      LayoutInflater inflater = getLayoutInflater(); 
      rl_main = (RelativeLayout) inflater.inflate(R.layout.newslisting,null); 

      ListView lv_Listing = (ListView) rl_main.findViewById(R.id.id_lv_news_listing); 
      LazyAdapter newsAdpater = new LazyAdapter(NewsListing.this, channel_id, db_Helper); 
      lv_Listing.setAdapter(newsAdpater); 
      lv_Listing.setDividerHeight(0); 

      TextView tv_channelNumber = (TextView)rl_main.findViewById(R.id.id_tv_ChannelNumber); 
      if(tv_channelNumber != null) 
      { 
       tv_channelNumber.setText("Some Text"); 
      } 

      TextView tv_channelName = (TextView)rl_main.findViewById(R.id.id_tv_ChannelName); 
      if(tv_channelName != null) 
      { 
       tv_channelName.setText("Some Text"); 
      } 

      lv_Listing.setOnItemClickListener(new OnItemClickListener() 
      { 

       @Override 
       public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
       { 
        // something on ListItem Click 
       } 
      });   

      publishProgress(); 
      index++; 
     }  
     return null; 
    } 

    @Override 
    protected void onProgressUpdate(Void... v) 
    { 

     super.onProgressUpdate(v); 
     try 
     { 
      viewFlipper.addView(rl_main); // Here I get the exception, but not on all the views 
     } 
     catch (Exception e) 
     { 
      // Exception 
     } 
    } 

    @Override 
    protected void onPostExecute(String result) 
    { 
     super.onPostExecute(result); 
     progressDialog.dismiss(); 
    } 
} 

(ボイド... V)、私はViewFlipperにビューを追加するとき、私は例外を取得するが、私はこれが表示されませんViewを追加するたびに例外が発生します。例外は次のとおりです。

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. in viewflipper 

答えて

0

は仕事をしました。その作業は完璧です。 AsyncTaskの問題は何だったのか分かりません。

1

おそらくLayoutInflater.inflateのオーバーロードされたバージョンを使用しshoud。あなたのコードで :

LayoutInflater inflater = getLayoutInflater(); 
rl_main = (RelativeLayout) inflater.inflate(R.layout.newslisting,null); 

使用代わりに、この方法:ブールattachToRootは(親)彼のルートに膨張したビューを添付するか、ではないためであるAndroid Developpers LayoutInflater.inflate

。 そのような虚偽のブール値を渡すようにしてください:スレッドとハンドラでAsyncTaskの交換

rl_main = (RelativeLayout) inflater.inflate(R.layout.newslisting,null, false); 
関連する問題