ViewStub'parent viewgroup

后端 未结 1 1286
情深已故
情深已故 2021-01-28 23:34

What is the meaning of that exception

ava.lang.IllegalStateException: ViewStub must have a non-null ViewGroup viewParent

i am creating an array of View Stub and

相关标签:
1条回答
  • 2021-01-28 23:47

    Your ViewStub don't have a parent, that's why you catch Exception. You must add ViewStub in Layout at first, after you can inflate it to another View.

    Why you use ViewStub? Do you really need it? Maybe it can be good solution:

    try {
        View.inflate(getApplicationContext(), R.layout.view_stub_layout, mainLayout);
    } catch(Exception e){
        e.getMessage();
    }
    

    If you need to keep added Views:

    try {
        views[i] = View.inflate(getApplicationContext(), R.layout.view_stub_layout, null);
        mainLayout.add(views[i]);
    } catch(Exception e){
        e.getMessage();
    }
    
    0 讨论(0)
提交回复
热议问题