문제

I extend ViewFlipper widget. When I initializ MyViewFlipper I pass List oа object to it. MyViewFlipper perform it list and add some views to MyViewFlipper.

My activity has android:configChanges="keyboardHidden|orientation", therefor my views hiererchy not recreating when device orientation changed.

Which method I must override in my MyViewFlipper to process orientation changed event to recreate my child views in MyViewFlipper?

How to do it others views?

Methid, that perform List of object in MyViewFlipper:

public void setUsers(List<User> users)
{
    removeAllViews();

    Display display = ((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int maxWidth = display.getWidth();

    screens = new LinearLayout[maxScreens];
    int fillingScreen = maxScreens;

    while(fillingScreen > 0) 
    {
        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
        linearLayout.setGravity(Gravity.CENTER);
        screens[fillingScreen - 1] = linearLayout;
        fillingScreen --;
    }

    int currentUser = 0;

    while(currentUser < users.size() && fillingScreen < maxScreens)
    {

        LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.item_people_category_item, null);
        ImageView iv = (ImageView) linearLayout.findViewById(R.id.item_people_category_item_avatar);

        screens[fillingScreen].addView(linearLayout);
        screens[fillingScreen].measure(0, 0);

        if (screens[fillingScreen].getMeasuredWidth() >= maxWidth)
        {
            screens[fillingScreen].removeView(linearLayout);
            addView(screens[fillingScreen]);
            fillingScreen ++;
        }
        else 
        {
            User user = users.get(currentUser);
            iv.setOnClickListener(ouUserClicked);
            linearLayout.setTag(user);
            App._IMAGEMANAGER.setImage(user.getPhoto(), iv, R.drawable.no_photo);
            currentUser++;
        }
    }

    if (fillingScreen < maxScreens && screens[fillingScreen].getParent() == null) addView(screens[fillingScreen]);
}

It simpe add some LinwarLayout to ViewFlipper with muximim possiable number of objects.

PS:

   @Override
    public void onConfigurationChange(Configuration newConf) {
      // notify view flopper here
    }

Other views in my layout not need to notify. They change representation self. Whih method they use for it? onMeauser()?

도움이 되었습니까?

해결책

You should override

 @Override
public void onConfigurationChanged(Configuration newConfig) {
 super.onConfigurationChanged(newConfig);
}

this to detect orientation changes...

다른 팁

It is not the method of view, nut method of activity:

@Override
public void onConfigurationChange(Configuration newConf) {
  // notify view flopper here
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top