开发者

how to click the popwindow in the actionbar?

I have created action bar.in that when i click on one of the menu a pop window should be displayed.I have done that.But after the pop up window displays i am not able to perform other function in my action bar.howw can i acheive that.I have posted my code.

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);




}

public void onTabSelected(Tab tab, FragmentTransaction ft) {

        mDisplayMode = tab.getPosition();
        System.out.println("text");

        // Do stuff based on new tab selected

    }


public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    // Do Nothing

}

public void onTabReselected(Tab tab, FragmentTransaction ft) {
    // Do nothing


}*/



        ActionBar bar = getActionBar();

开发者_Go百科        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        ActionBar.Tab tabA = bar.newTab().setText("Home");
        ActionBar.Tab tabB = bar.newTab().setText("Listings");
        ActionBar.Tab tabC = bar.newTab().setText("Remote");
        Fragment fragmentA = new ATab();
        Fragment fragmentB = new BTab();
        Fragment fragmentC = new CTab();
        bar.setDisplayShowHomeEnabled(true);
        tabA.setTabListener(new MyTabsListener(fragmentA));
        tabB.setTabListener(new MyTabsListener(fragmentB));
        tabC.setTabListener(new MyTabsListener(fragmentC));
        bar.addTab(tabA);
        bar.addTab(tabB);
        bar.addTab(tabC);

    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.option, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.settings:
            newGame();
            return true;
        case R.id.help:
            // showHelp();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    private void newGame() {




         LayoutInflater inflater = (LayoutInflater)
           this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        PopupWindow pw = new PopupWindow(
           inflater.inflate(R.layout.settings, null, true), 300, 600, true);

        // The code below assumes that the root container has an id called 'main'

        pw.showAtLocation(this.findViewById(R.id.settings), Gravity.RIGHT, 0, 0); 


    }

    protected class MyTabsListener implements ActionBar.TabListener {
        private Fragment mfragment;

        public MyTabsListener(Fragment fragment) {
            this.mfragment = fragment;

        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            ft.add(R.id.fragment_place, mfragment, null);

        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
            ft.remove(mfragment);

        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜