Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RemoveAllViews not removing views

I try to remove all child views of a linear layout but nothing is removed, the weird thing is the same code is working in another application. Here's the sample code of the method that populate the choiceHolder whenever a tab in it is selected (I remove all view and mark the selected one and populate basing on that:

/** a method to fill the upper bar where we choose the {@link CategoriesMyBox}
 * @param category
 */
private void fillNavigationBar( CategoriesGetter category) {
    TextView categoryTxt = new TextView(getActivity());
//      categoryTxt.setAllCaps(true);
        LinearLayout.LayoutParams txtParams;
        if (category.isSelected() /*|| (category.getId_categorie()==0 && allselected)*/) {
        txtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        txtParams.gravity = Gravity.CENTER;
        categoryTxt.setGravity(Gravity.CENTER);
        categoryTxt.setTextSize(categoryTxt.getTextSize());
        txtParams.setMargins(10, 0, 10, 0);
        categoryTxt.setPadding(5, 5, 5, 5);
        if (category.getId_categorie() == 0) {
            categoryTxt.setText(getResources().getString(R.string.all_boxs));
        }else {
            categoryTxt.setText(category.getName_categorie());
        }
        categoryTxt.setTextColor(Color.GREEN);
        categoryTxt.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_categories_selected));
//          categoryTxt.setBackgroundColor(Color.parseColor("#E3E8E6"));
        categoryTxt.setTag(category);


    }else {

        txtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        txtParams.setMargins(10, 0, 10, 0);
        categoryTxt.setGravity(Gravity.CENTER);
        categoryTxt.setPadding(5, 5, 5, 5);
        txtParams.gravity = Gravity.CENTER;
        if (category.getId_categorie() == 0) {
            categoryTxt.setText(getResources().getString(R.string.all_boxs));
        }else {
            categoryTxt.setText((category.getName_categorie()));
        }
        categoryTxt.setTextColor(Color.GRAY);
        categoryTxt.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_categories));
//          categoryTxt.setBackgroundColor(Color.parseColor("#777777"));
        categoryTxt.setTag(category);
    }
    choiceHolder.addView(categoryTxt, txtParams);
    categoryTxt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            CategoriesGetter cat = (CategoriesGetter)v.getTag();
            id_cat = cat.getId_categorie();
            for (int i = 0; i < categories.size(); i++) {
                categories.get(i).setSelected(false);
            }
                cat.setSelected(true);
    //              choiceHolder.removeAllViews();
            /*for(int i=0; i<((ViewGroup)choiceHolder).getChildCount(); ++i) {
                View nextChild = ((ViewGroup)choiceHolder).getChildAt(i);
                choiceHolder.removeView(nextChild);
            }*/
            while (((ViewGroup)choiceHolder).getChildCount() >0) {
                View nextChild = ((ViewGroup)choiceHolder).getChildAt(0);
                choiceHolder.removeView(nextChild);
            }
//              choiceHolder.removeAllViewsInLayout();
            for (int i = 0; i < categories.size(); i++) {

                fillNavigationBar(categories.get(i));
            }
            callbackCategory.selectCategory(cat.getId_categorie());





        }
    });
}

choiceHolder is a LinearLayout.

and here's a picture showing the problems : enter image description here

Well all my application is behaving the same way even when updating the list inside i can still see the list that was before.

like image 393
Driss Bounouar Avatar asked Jan 10 '14 10:01

Driss Bounouar


1 Answers

the solution i found for this problem is remove the fullScreen theme tag from the activity in the AndroidManifest it was like this :

<application
    android:name="com.paperpad.mybox.ApplicationInit"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.paperpad.mybox.activities.SplashActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.crashlytics.ApiKey"
        android:value="023e7fe8a4a93f93ffe7510201929d081b125313" />

    <activity
        android:name="com.paperpad.mybox.activities.BoxsMainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_boxs_main"
        android:theme="@style/FullscreenTheme" >
    </activity>
    <activity
        android:name="com.paperpad.mybox.LoginActivity"
        android:label="@string/title_activity_login"
        android:windowSoftInputMode="adjustResize|stateVisible" >
    </activity>
</application>

by removing android:theme="@style/FullscreenTheme" from the activity BoxsMainActivityall worked. hope this helps someone...

like image 72
Driss Bounouar Avatar answered Oct 11 '22 19:10

Driss Bounouar