0

On create i am creating my layout problematically.After that on click on button i want to remove the previous layout content How could i do that i tried that removeView.But it didn't worked for me .Here is my code

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);
                }

AFter on create on click of a button i have again call this function and at that time when i calling this it is appending the result .I am want new result on the click of the button what i have to do for this Please help me

And my xml file

<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>
Developer
  • 6,292
  • 19
  • 55
  • 115

1 Answers1

0
View.setVisibility(View.GONE);
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
  • u want to remove LinearLayout? – KOTIOS Jul 31 '13 at 07:10
  • ya on create it will create the layout and the set the values after that when i will click on the button again it add fresh layout and it new values in it – Developer Jul 31 '13 at 07:11
  • see in the question in the linear layout i am putting a layout so i want to blank the layout then again put a new layout in it – Developer Jul 31 '13 at 07:13
  • try this :scrollview.removeAllViews() and then add new one – KOTIOS Jul 31 '13 at 07:16
  • i have done like this flightResult.setVisibility(View.GONE); on click of button after that i called my function setData .but i blanked my page – Developer Jul 31 '13 at 07:17
  • after adding try set its visiblity to View.Visible and let me know the result – KOTIOS Jul 31 '13 at 07:18
  • ok do one think when u r dynamically creating ur layout dont put layout in xml try all things from code itself – KOTIOS Jul 31 '13 at 07:25
  • in the flightResultData i am putting layout so there is not other way so that on click of the button it blanks the flightResultData then again i put new layout in it – Developer Jul 31 '13 at 07:32