如何刷新布局

时间:2014-10-29 10:59:04

标签: java android layout

我想删除添加的文本字段,并根据从微调器中选择的内容添加其他文本字段。 这是我的代码: 在xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f4f4f4"
android:id="@+id/taskoptionfragmentlinearlayout" > 


 <TextView
        android:layout_marginTop="10dp"
        android:textStyle="bold"
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select A Search Option" />
    <Spinner
       android:layout_marginTop="20dp"
        android:id="@+id/gis_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
         />  
    </LinearLayout> 
课堂上的

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)        
  {
    final View rootView = inflater.inflate(R.layout.fragment_tasklist_options, container, false);

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
          ll = (LinearLayout)rootView.findViewById(R.id.taskoptionfragmentlinearlayout);
            //create textfields....
            TextView tv = new TextView(getActivity());
            tv.setText(INPUTFLDLABELAArray.get(i));
            tv.setGravity(Gravity.RIGHT);
            tv.setTextSize(18);
            tv.setTypeface(Typeface.DEFAULT_BOLD);
            tv.setPadding(0, 0, 15, 0);
            ll.addView(tv);
        } 

我总结了代码以简化它。 因此,当选择微调器中的项目时,将显示文本字段。然后,当选择另一个项目时,文本字段显示在前一个文本字段下。所以我想要的是(刷新/重置)布局,以便每次选择一个项目时,旧的文本字段将被删除,并添加新的文本字段。

1 个答案:

答案 0 :(得分:0)

尝试在添加新内容之前调用ll.removeAllViews()