Note that there are some explanatory texts on larger screens.

plurals
  1. POView added not getting removed even removeAllViews () is invoked
    primarykey
    data
    text
    <p>I am facing problems in removing views even after calling removeAllviews(). Onclick of textView i am adding textView and imageView to layout. Next time when i click textView previously present textview and imageview is not getting removed and is getting appended with th news ones inspite of calling removeAllViews().</p> <p>Any help is appreciated.</p> <p>Code is </p> <p>Activity code </p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.check); content=(LinearLayout)findViewById(R.id.content); today=(TextView)findViewById(R.id.today); tomorrow=(TextView)findViewById(R.id.tomorrow); today.setOnClickListener(new TextView.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //Toast.makeText(ToDo.this, "Before"+content.getChildCount(), Toast.LENGTH_LONG).show(); content.removeAllViews(); inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id=0; for (int idx = 0; idx &lt; 4; idx++) { id = idx + 1; rel = (RelativeLayout) inflater.inflate(R.layout.data, null); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); params.setMargins(0, 50, 0, 0); txt = (TextView) rel.findViewById(R.id.txt); txt.setText("AAA"+idx); img = (ImageView) rel.findViewById(R.id.img); img.setImageResource(R.drawable.stub); img.setId(id); img.setOnClickListener(new ImageView.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(ToDo.this,"Selected" + v.getId(),Toast.LENGTH_LONG).show(); } }); content.addView(rel, params); } content.setVisibility(View.VISIBLE); Toast.makeText(ToDo.this, ""+content.getChildCount(), Toast.LENGTH_LONG).show(); } }); tomorrow.setOnClickListener(new TextView.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //Toast.makeText(ToDo.this, "Before"+content.getChildCount(), Toast.LENGTH_LONG).show(); content.removeAllViews(); inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id=0; for (int idx = 0; idx &lt; 4; idx++) { id = idx + 1; rel = (RelativeLayout) inflater.inflate(R.layout.data, null); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); params.setMargins(0, 50, 0, 0); txt = (TextView) rel.findViewById(R.id.txt); txt.setText("Tomo"+idx); img = (ImageView) rel.findViewById(R.id.img); img.setImageResource(R.drawable.stub); img.setId(id); img.setOnClickListener(new ImageView.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(ToDo.this,"Selected" + v.getId(),Toast.LENGTH_LONG).show(); } }); content.addView(rel, params); } content.setVisibility(View.VISIBLE); Toast.makeText(ToDo.this, ""+content.getChildCount(), Toast.LENGTH_LONG).show(); } }); } </code></pre> <p>check.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;RelativeLayout android:layout_width="250dp" android:id="@+id/whiteboard" android:layout_height="300dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="60dp" android:background="#FFFFFF" &gt; &lt;Button android:id="@+id/add" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="17dp" android:layout_marginLeft="20dp" android:text="Add" /&gt; &lt;View android:id="@+id/bottomseperator" android:layout_width="200dp" android:layout_height="1dp" android:layout_above="@+id/add" android:layout_alignLeft="@+id/add" android:layout_marginBottom="10dp" android:background="#000000" /&gt; &lt;View android:id="@+id/topseperator" android:layout_width="220dp" android:layout_height="1dp" android:layout_marginTop="35dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:background="#000000" /&gt; &lt;TextView android:id="@+id/day" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="20dp" android:layout_marginTop="8dp" android:textSize="15sp" android:text="Day :"/&gt; &lt;TextView android:id="@+id/today" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/day" android:layout_alignBottom="@+id/day" android:layout_toRightOf="@+id/day" android:textSize="15sp" android:text="Today /" /&gt; &lt;TextView android:id="@+id/tomorrow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/today" android:layout_alignBottom="@+id/today" android:layout_toRightOf="@+id/today" android:textSize="15sp" android:text="Tomorrow /" /&gt; &lt;TextView android:id="@+id/custom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/tomorrow" android:layout_alignBottom="@+id/tomorrow" android:layout_toRightOf="@+id/tomorrow" android:textSize="15sp" android:text="Custom" /&gt; &lt;ScrollView android:id="@+id/contenntscroll" android:layout_width="200dip" android:layout_height="200dip" android:layout_alignBottom="@+id/whiteboard" android:layout_alignTop="@+id/whiteboard" android:layout_marginLeft="20dp" android:layout_marginTop="10dp" android:layout_below="@+id/topseperator" android:isScrollContainer="false" android:scrollbars="none"&gt; &lt;LinearLayout android:id="@+id/content" android:layout_width="200dp" android:layout_height="300dp" android:layout_marginTop="30dp" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;/RelativeLayout&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload