1

I have tried using invalidate() to refresh my view, and it will not work. I know there is another way to refresh using draw(Canvas canvas).

Could someone explain to me how and why to use the draw method? What is the Canvas? (is that the view I would like redrawn?)

This is some sample code in how it would be used:

    if(pageNumber == 1)
    {
        if(pageCount == --lastPageCount)
        {
            page2Layout.setVisibility(View.GONE);
            page1Layout.setVisibility(View.VISIBLE);
        }
        if(created1 == false)
        {
            help.setOrientation(LinearLayout.HORIZONTAL);
            help.setLayoutParams(params);

            helpText.setLayoutParams(params);
            helpText.setText("TEST!\n\n" + 
                    "test\n" +
                    "Test");

            help.addView(helpText);
            page1Layout.addView(help);
            newSheetLayoutV.addView(page1Layout);
            created1 = true;
        }
    }

There is also another part/parts to this code which is not working as it should (this is why I need to use the refresh).

    else if(pageNumber == 4)
    {
        if(pageCount == ++lastPageCount)
        {
            page3Layout.setVisibility(View.GONE);
            page4Layout.setVisibility(View.VISIBLE);
        }
        else if (pageCount == --lastPageCount)
        {
            page5Layout.setVisibility(View.GONE);
            page4Layout.setVisibility(View.VISIBLE);
        }

        if(created4 == false)
        {
            LinearLayout horizontalPageLayout = new LinearLayout(this);
            horizontalPageLayout.setOrientation(LinearLayout.HORIZONTAL);
            horizontalPageLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

            TextView testText = new TextView(this);
            testText.setLayoutParams(params);
            testText.setText("Test!");

            page4Layout.addView(testText);

            newSheetLayoutV.addView(page4Layout);

            created4 = true;
        }
    }

Essentially the code works fine, except for the refresh when I remove the view page1Layout.setVisibility(View.GONE);, and add a new view to the layout!

Thanks for your help!

1 Answer 1

0

Fixed, added the visibility(View.GONE); and addView to the creation of the layouts, then just make the layouts visible when there was a need for them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.