0

在创建时我正在创建我的布局有问题。之后单击按钮我想删除以前的布局内容我怎么能这样做我尝试了removeView。但它对我不起作用。这是我的代码

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>
4

1 回答 1

0
View.setVisibility(View.GONE);
于 2013-07-31T07:08:15.407 回答