I am using Android APi 3. I built a container control that contains two controls: another container (layout) and a ListView.
In the main container control, I overrode onLayout function to change visibility of a child view to GONE / VISIBLE depending on items in the list control (2nd child view).
Problem is, when I use GONE and then an event triggers and set it to VISIBLE, the first child control shows but then ListView doesn't show the开发者_开发问答 item - ListView clearly has one item.
Perhaps onLayout may not be the last place to call setVisibility of child controls. If not, what is the best place?
For my problem, using INVISIBLE fixes problem instead of GONE.
below is the code: @Override protected void onLayout(boolean changed, int l, int t, int r, int b) {
/* if there's no data to display, hide headerView */
if (listView.getAdapter() == null || listView.getAdapter().getCount() == 0)
headerView.setVisibility(INVISIBLE); // if set to GONE, it won't display the listView when there's only one item or unless it's refreshed 2nd time.
else
headerView.setVisibility(VISIBLE);
super.onLayout(changed, l, t, r, b);
}
Any thoughts?
probably you need to refresh the whole listView using yourAdapter.notifyDataSetChanged();
did you do that...?
精彩评论