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>