【问题标题】:Blank the layout containing a Layout in Android On click在Android中将包含布局的布局清空单击
【发布时间】:2013-07-31 07:06:31
【问题描述】:

在创建时我正在创建我的布局有问题。点击按钮后我想删除以前的布局内容我怎么能这样做我尝试了 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>

【问题讨论】:

  • 你试过gone property了吗?
  • 点击按钮或在函数中我必须在 android 中发现新的地方

标签: android android-layout android-inflate


【解决方案1】:
View.setVisibility(View.GONE);

【讨论】:

  • 你想删除 LinearLayout 吗?
  • 在线性布局的问题中看到我正在放置一个布局,所以我想空白布局然后再次在其中放置一个新布局
  • 试试这个 :scrollview.removeAllViews() 然后添加新的
  • 我已经这样做了 flightResult.setVisibility(View.GONE);之后点击按钮,我调用了我的函数 setData 。但我空白了我的页面
猜你喜欢
  • 2011-08-03
  • 1970-01-01
  • 2021-04-10
  • 2016-04-05
  • 1970-01-01
  • 1970-01-01
  • 2012-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多