0

Здравствуйте.

У меня проблема: не могу перерисовать View.

View view = null;
ViewPager pager = null;
TabPageIndicator tabIndicator = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);

    linearlayout = (LinearLayout) findViewById(R.id.LinearLayout1e);
    linearlayout.addView(TabPage(0), new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    Button but = (Button) findViewById(R.id.act_bar_button_home);
    but.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            linearlayout.addView(TabPage(1), new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        }
    });
}

public View TabPage(int i) {
    if (i == 1) {
        pager.removeAllViews();
    }

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = new View(this);
    view = inflater.inflate(R.layout.main_tab_layout, null);

    pager = (ViewPager) view.findViewById(R.id.pager);
    pager.setAdapter(new CustomFragmentAdapter(getSupportFragmentManager()));

    tabIndicator = (TabPageIndicator) view.findViewById(R.id.indicator);
    tabIndicator.setViewPager(pager);
    tabIndicator.notifyDataSetChanged();

    return view;
}

При запуске программы, view отображается. А при нажатии кнопки view удаляется, но заново не появляется. В чём может быть проблема? Подскажите, пожалуйста.

1 ответ 1

1

Решил сам. Просто за вместо pager.removeAllViews(); поставил pager.setAdapter(null); и в onClick добавил linearlayout.removeAllViews();

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.