I am using a listview inside a popup window and listview shows some dynamic contents. I want to set height of the listview, based on contents but it should not exceed a particular height.Since i couldn't set a maximum height to that listview, I changed the height of the listview from it's adapters getview and used wrapcontent in layout. Listview height is changing when the content size is increasing. But the size is not changing while the content size is decreasing.

    if(co_get>11)
{               
    LayoutParams params =  new LayoutParams(LayoutParams.MATCH_PARENT, 600); 
    params.setMargins(10, 10, 10, 10);     
    parent.setLayoutParams(params);

}
else
{           
        LayoutParams params =  new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
        params.setMargins(10, 10, 10, 10);          
        parent.setLayoutParams(params);

}

And this is the code that i used in getview.

有帮助吗?

解决方案

I set Layoutparams to listview when it is notified. and that solved the problem.

其他提示

The onPrepareDialog() method is called just before each time the Dialog is displayed allowing you to update it appropriately.

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    //Always call through to super implementation
    // your changings
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top