I have a problem: I can not redraw the 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; } 

When the program starts, the view is displayed. And when you click the button, the view is deleted, but does not appear again. What could be the problem? Tell me please.

    1 answer 1

    I decided myself. Just for instead of pager.removeAllViews (); put pager.setAdapter (null); and in onClick added linearlayout.removeAllViews ();