2013-07-31 99 views
0

創建我創建我的佈局有問題。然後點擊按鈕我想刪除以前的佈局內容我怎麼能這樣做,我試過removeView。但它沒有爲我工作。這裏是我的代碼空白在Android中的佈局包含佈局點擊

void setDate(){ 

      flightResult=(LinearLayout)findViewById(R.id.flightResultData); 
      LinearLayout.LayoutParams flightDetailsLayout = new LinearLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
      LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      LinearLayout.LayoutParams forUnderLine = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
        LayoutParams.WRAP_CONTENT); 
      forUnderLine.setMargins(0,0, 0, 0); 

      flightDetailsLayout.setMargins(0, 40, 0, 0); 
      for(int i=0;i < 5;i++){ 
       TextView line=new TextView(this); 
       line.setBackgroundResource(R.layout.shape_line); 
       line.setLayoutParams(forUnderLine); 
       if(i!=0){ 
        flightResult.addView(line); 
       } 
       LinearLayout flightInformations=(LinearLayout)inflater.inflate(R.layout.flight_details_layout, null); 
       flightLogo=(ImageView)flightInformations.findViewById(R.id.flightLogo); 
       flightCompany = (TextView)flightInformations.findViewById(R.id.flightCompany); 
       flightLogo.setImageResource(R.drawable.airindia); 
       flightCompany.setText("AirIndia"); 
       flightResult.addView(flightInformations); 
      } 
      TextView dummy=new TextView(this); 
      dummy.setLayoutParams(flightDetailsLayout); 
      flightResult.addView(dummy); 
       } 

後上創建一個按鈕的點擊我已經再次調用這個函數,並在當我調用這個那個時候它是附加的結果。我是希望有新的結果點擊按鈕我要爲此做什麼請幫助我

而我的xml文件

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_below="@+id/sortFlightLayouts"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:id="@+id/flightResultData" 
      android:orientation="vertical"> 
     </LinearLayout> 

    </ScrollView> 
+0

你試過了嗎? – KOTIOS

+0

在那裏我不得不disi我在Android的新點擊按鈕或在功能 – Developer

回答

0
View.setVisibility(View.GONE); 
+0

何時你想刪除此視圖?我想點擊右鍵? – KOTIOS

+0

你想刪除LinearLayout? – KOTIOS

+0

雅在創建它將創建佈局和設置值之後,當我將再次點擊該按鈕時,它會添加新的佈局和它的新值 – Developer