Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid adding and removing textviews in linearlayout programatically
    primarykey
    data
    text
    <p>I am trying to add <strong>views(TextView)</strong> in linearlayout prgramatically. I am able to add textview in linearlayout programatically.</p> <p>Here is my code to add textview:</p> <pre><code>public void setSelectedContactTextView(final ArrayList&lt;Object&gt; list){ //Constants.progressDialog=ProgressDialog.show(this, "", Constants.MSG_PROGESSDIALOG); /* new Thread(new Runnable() { @Override public void run() {*/ runOnUiThread(new Runnable() { @Override public void run() { while(i&lt;list.size()){ ContactBean contactBean=(ContactBean)list.get(i); if(contactBean.isSelected()==true){ View line = new View(NewEventShowDetails.this); line.setLayoutParams(new LayoutParams(1, LayoutParams.WRAP_CONTENT)); final TextView contactTextView=new TextView(NewEventShowDetails.this); contactTextView.setText(contactBean.getEmailId().toString()); contactTextView.setPadding(3,3, 3, 3); contactTextView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(NewEventShowDetails.this, contactTextView.getText(), Toast.LENGTH_SHORT).show(); } }); fbContactTextLinearLayout.addView(contactTextView); fbContactTextLinearLayout.addView(line); count++; } i++; } } }); /*} });*/ } </code></pre> <p><strong>I am calling setSelectedContactTextView() from OnResume() in activty. It adds textviews in activity first time but after calling removeAllTextViewsFromLayout() it won't add textviews again.</strong></p> <p>Here is the code to remove textview:</p> <pre><code>public void removeAllTextViewsFromLayout(){ final int childcount = fbContactTextLinearLayout.getChildCount(); runOnUiThread(new Runnable() { @Override public void run() { for (int i=0; i &lt; childcount; i++){ fbContactTextLinearLayout.removeViewInLayout(fbContactTextLinearLayout.getChildAt(i)); } } }); } </code></pre> <p><strong>This is defined in OnCreate()</strong></p> <pre><code>fbContactTextLinearLayout=(LinearLayout)findViewById(R.id.fbcontact_text_layout); </code></pre>
    singulars
    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.
 

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