0

I inflate my custom-classed-layout but I can't access findViewById on this inside the constructor because the fields don't exist yet.

I can't use onLayout because onLayout is called whenever children are added/removed so my code runs multiple times when I only want it to run once.

I tried onLayoutFinished, but that doesn't always work.

I would like to leverage something like a onInitialLayoutFinished which of course isn't a real system function. What should I be using here?

4

2 回答 2

1

onLayoutFinished method doesn't exist. You have to Override onFinishInflate:

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();    
        mListView = (ListView) findViewById(R.id.listView);
    }

DOC

于 2012-09-25T16:00:07.927 回答
1

Have you tried:

@Override

protected void onFinishInflate()

{
    // TODO Auto-generated method stub
    super.onFinishInflate();
}
于 2012-09-25T16:03:02.650 回答