logo
down
shadow

Toolbar addView not working


Toolbar addView not working

By : Yogesh Kumar
Date : November 24 2020, 03:01 PM
will help you The easiest way to do this is by taking the whole layout item_toolbar_main and set it in a Toolbar directly in xml without using any Java code. So change the Toolbar view in your layout activity_main.xml to something like this:
code :
<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorWhite"
        android:paddingBottom="@dimen/activity_margin_quarter"
        android:paddingLeft="@dimen/activity_margin_half"
        android:paddingRight="@dimen/activity_margin_half"
        app:contentInsetEnd="@dimen/activity_margin_zero"
        app:contentInsetLeft="@dimen/activity_margin_zero"
        app:contentInsetRight="@dimen/activity_margin_zero"
        app:contentInsetStart="@dimen/activity_margin_zero"
        app:layout_scrollFlags="scroll|enterAlways">

             <include layout="@layout/item_toolbar_main"/>

</android.support.v7.widget.Toolbar>


Share : facebook icon twitter icon
RemoteView addView not working

RemoteView addView not working


By : ruffner
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The addView() method needs the id of the view inside the layout you want to add this new view to, not the layout itself.
Instead of this:
code :
views.addView(views.getLayoutId(), newView);
views.addView(R.id.view_container, newView);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/view_container"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <!-- New views will be added here at runtime -->
    </LinearLayout>
</LinearLayout>
ViewFlipper addView not working

ViewFlipper addView not working


By : Nicoolas
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I was able to find the answer to my question. I was removing all children from the ViewFlipper and the next step was to add new children to the ViewFlipper. Removing all children and invalidating the view was resulting in a blank view, due to no child was selected. By only adding new children and again invalidating the view, the ViewFlipper stayed blank. By using ws.showNext() after ws.invalidate(), the first child from the new children is shown and the ViewFlipper works as expected. Hope this helps.
code :
            ws.removeAllViews();
            ArrayList<View> childViews = getAllChildrenFromSomewhere();
            for (View childView : childViews) {
                ws.addView(childView);
            }
            ws.onFinishTemporaryDetach();

            ws.onFinishInflate();
            ws.invalidate();  
            // show the first childView
            ws.showNext();
addView FILL_PARENT not working

addView FILL_PARENT not working


By : Namit Vatsyayan
Date : March 29 2020, 07:55 AM
it fixes the issue Use this addView method. By the way don't use getBaseContext() unless you know why you are using it, instead use context of an activity (this).
code :
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
    ViewGroup parent = (ViewGroup) findViewById(R.id.host_layout);
    View view = LayoutInflater.from(this).inflate(R.layout.vitrin_layout, null);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT); 
    parent.addView(view, params);

    setTitle(getString(R.string.title_activity_vitrin));
}
addView not working

addView not working


By : wu hai
Date : March 29 2020, 07:55 AM
wish helps you I found my mistake. I was calling the the above function(of MainActivity) through an AsyncTask class(by a listener) and rather than calling in OnPostExecute I was calling at end of doInBackground.
i dont understand this line ((LinearLayout)addView.getParent()).removeView(addView);

i dont understand this line ((LinearLayout)addView.getParent()).removeView(addView);


By : 冯俊杰
Date : March 29 2020, 07:55 AM
will help you , We'll evaluate this step-by-step.
First, this is evaluated:
code :
addView.getParent()
(LinearLayout)addView.getParent()
shadow
Privacy Policy - Terms - Contact Us © voile276.org