-1

我正在开发购物应用程序,一切准备就绪,在主活动扩展 ActionBarActivity.on 这个活动 leftDrawermenu,Fragment 的 tabhost。当抽屉打开时,onBackPress 运行并执行 exitConfirmDialog 但如果抽屉关闭,则 exitConfirmdialog 不显示并直接关闭

public class MainActivity extends ActionBarActivity implements
             OnTabChangeListener,OnTouchListener, OnBackStackChangedListener {



    /** The Sliding list view. */
        private ListView mSlidingListView;

        /** The Main adapter data. */
        private ArrayList<Category> mMainAdapterData;

        /** The Sliding adapter. */
        private SlidingAdapter mSlidingAdapter;

        /** The catalog xml parser. */
        private CatalogXmlParser catalogXmlParser;

        /** The Drawer toggle. */
        private ActionBarDrawerToggle mDrawerToggle;

        /** The Drawer layout. */
        private DrawerLayout mDrawerLayout;

        /** The Toolbar. */
        private Toolbar mToolbar;

        /** The Ab cart counter. */
        public static TextView mAbCartCounter;

        /** The Ab title. */
        private TextView mAbTitle;

        /** The Ab search. */

        /** The Ab checkout. */
        private View mAbCheckout;

        /** The Ab cart image view. */
        public static View mAbCartImageView;

        /** The Ab login cart image view. (added by nayan)*/
        //private View mAbLoginImageView;
        public View mAbLoginImageView;
        private int ExitFlag=1;

        /** The Ab clear filter. */
        //private View mAbClearFilter;

        /** The Ab search et. */
        private EditText mAbSearchEt;

        /** The Ab cancel search. */
        private View mAbCancelSearch;

        /** The Search text watcher. */
        private SearchTextWatcher mSearchTextWatcher;

        /** The Ab sent. */
        private View mAbSent;

        private Context mContext;

        @SuppressWarnings("deprecation")
        private LocalActivityManager mLocalActivityManager;

        private Bundle savedInstanceState_;

        public List<List<Product>> AdapterData;

        public boolean IsHaveSlider;

        public TabHost tabHost;

        private TextView tabtext;

        private HorizontalScrollView scroll_Focus;
        public static  Set<String> Cart_ProductList = new HashSet<String>();
        public boolean first_Time=true;

        private int tab;

        private View login_lbl;

        private RelativeLayout layout_Cart;

        private Toast toast;

        private ImageView mAbSearch;

        private View mAbClearFilter;    

        public String Current_Fragment_flag;

        public static LinearLayout container;

        public static EditText sampleImage;

        private int AnimationState=0;

        /*
         * (non-Javadoc)
         * 
         * @see android.support.v7.app.ActionBarActivity#onCreate(android.os.Bundle)
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {

            this.mContext = getBaseContext();

            ThemesManager.setCorrectTheme(this, AppSettings.CURRENT_THEME);

            super.onCreate(savedInstanceState);

            savedInstanceState_=savedInstanceState;
            MainSplashScreen.isfirsttime=false;

            setContentView(R.layout.activity_main);

            mSearchTextWatcher = new SearchTextWatcher();

            ImageLoaderConfiguration imageLoaderConfiguration = ImageOptionsBuilder
                    .createImageLoaderConfiguration(this);
            ImageLoader.getInstance().init(imageLoaderConfiguration);

            catalogXmlParser = CatalogXmlParser.getInstance();

            catalogXmlParser.parseData(this);

            mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            sampleImage = (EditText) findViewById(R.id.sampleEDT);
            container = (LinearLayout) findViewById(R.id.main_placeholder);


            initActionbar();

          //ADDED BY NAYAN FOR INVISIBLE LOGIN BUTTON FROM ACTIONBAR IF ALREADY LOGGED
            mAbLoginImageView = findViewById(R.id.ab_login_card);
            login_lbl=findViewById(R.id.login_lbl);
            sampleImage.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub
                    if(AnimationState==0)
                    {
                        mAbCartCounter.animate().rotationYBy(720).setDuration(2000);

                    }

                    mAbCartCounter.animate().setListener(new AnimatorListener() {

                        @Override
                        public void onAnimationStart(Animator arg0) {
                            // TODO Auto-generated method stub
                            AnimationState=1;
                        }

                        @Override
                        public void onAnimationRepeat(Animator arg0) {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onAnimationEnd(Animator arg0) {
                            // TODO Auto-generated method stub
                            AnimationState=0;
                        }

                        @Override
                        public void onAnimationCancel(Animator arg0) {
                            // TODO Auto-generated method stub

                        }
                    });
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub

                }
            });

            boolean isLogges = ApplicationPreference.getLogInStatus();
            if (isLogges!=true)

            {
                mAbLoginImageView.setVisibility(View.VISIBLE);
                login_lbl.setVisibility(View.VISIBLE);
                mAbCartImageView.setVisibility(View.GONE);
                mAbCartCounter.setVisibility(View.GONE);

            }
            else
            {
                mAbLoginImageView.setVisibility(View.INVISIBLE);
                login_lbl.setVisibility(View.INVISIBLE);

                mAbCartImageView.setVisibility(View.VISIBLE);
                mAbCartCounter.setVisibility(View.VISIBLE);
            }
            //END NAYAN
            tabhost();  

            mAbCartImageView.setClickable(true);


            mAbCartCounter.setClickable(true);

            layout_Cart=(RelativeLayout)findViewById(R.id.layout_Cart);
            layout_Cart.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    int is_cart_visible=mAbCartImageView.getVisibility();
                    if(is_cart_visible==0)
                    {
                        //  showCartFragment(true, false);

                        /*  PopupWindow m_PopUpWindow = new PopupWindow(MainActivity.this);
                          m_PopUpWindow.setContentView(v);
                          m_PopUpWindow.setHeight(50);
                          m_PopUpWindow.setWidth(50);
                          m_PopUpWindow.showAsDropDown(v,300,5);*/

                    //  mAbCartImageView.setClickable(false);
                    //  mAbCartCounter.setClickable(false);
                          boolean isLogges = ApplicationPreference.getLogInStatus();
                            if(isLogges==false)
                            {
                                Toast.makeText(mContext,
                                        mContext.getString(R.string.pls_login),
                                        Toast.LENGTH_LONG).show();  
                            }else
                            {
                                if(Integer.parseInt(mAbCartCounter.getText().toString())>0)
                                {
                                //  mAbCartImageView.setBackgroundColor(Color.GREEN);
                                    //mAbCartCounter.setError("Please Wait....");
    //                              boolean addToBackStack=false; 
    //                              boolean clearBackStack=false;
    //                              FragmentDirectOrder FragmentDirectOrder1 = new FragmentDirectOrder("").newInstance();
    //                              //fragmentLogin.TAG="Login";
    //                              showScreen(FragmentDirectOrder1, FragmentDirectOrder1.TAG, addToBackStack,clearBackStack);
                                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                    builder.setMessage("please Wait...");
                                    AlertDialog dialog = builder.show();

                                    // Must call show() prior to fetching text view
                                    TextView messageView = (TextView)dialog.findViewById(android.R.id.message);
                                    messageView.setGravity(Gravity.CENTER);

                                    Intent orderBooking = new Intent(MainActivity.this, OrderBookingScreen.class);
                                    orderBooking.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    orderBooking.putExtra("CALLING", "cart");
                                    startActivity(orderBooking);
                                }
                                else
                                {
                                    Toast toast= Toast.makeText(getApplicationContext(),"Please select the product.",Toast.LENGTH_LONG);  
                                     LinearLayout linearlayout=(LinearLayout)toast.getView();
                                     TextView msgtext=(TextView)linearlayout.getChildAt(0);
                                     msgtext.setTextSize(12);
                                     toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL,70,3);
                                 //  toast.setMargin(10, 10);
                                     toast.show();
                                }
                                    /*   for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
                         {           
                             TextView tabtext_2=(TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
                             tabtext_2.setTextColor(Color.BLACK);            
                             tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
                             tabHost.clearFocus();
                         }*/
                    }
                    }else
                    {
                        Intent login_form = new Intent(MainActivity.this, FragmentLogin.class);
                        startActivity(login_form);
                    }
                }
            });
        //  overridePendingTransition(R.anim.fade_in, R.anim.fade_out);



        }

在后按片段

public void onBackPressed() {
    if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawer(GravityCompat.START);
        Toast.makeText(this, "DrawerClosed", Toast.LENGTH_LONG).show();
    } else if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
        getSupportFragmentManager().popBackStack();
        Toast.makeText(this, "popBackStack", Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(this, "popBackStack", Toast.LENGTH_LONG).show();
        super.onBackPressed();
    }
}
4

1 回答 1

0
mParentView.setFocusableInTouchMode(true);
        mParentView.requestFocus();
        mParentView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {

                if (keyCode == KeyEvent.KEYCODE_BACK){

                    if(ExitFlag == 1)
                    {
                         ExitFlag++;
                        getActivity().getSupportFragmentManager().popBackStack();
                        getActivity().onBackPressed();
                    }
                    else
                    {
                        ExitFlag = 1;
                    }
                }


                return true;
            }
        });
于 2015-09-08T13:15:19.683 回答