-1

I am developing a android app where I have created Customize alert dialog. I declare Globally alert dialog and and AlertDialog.builder as follow. Now I am calling three method f1(), f2(),f3(), in button click.

btn_my_order.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
      f1();
      f2(); 
      f3();
  return false;
        }
    });

I Declared orderDialog and builde globally as follow :-

 private AlertDialog orderDialog = null;
 AlertDialog.Builder builder;

My f1() block is as follow :-

       F1{

        builder = new AlertDialog.Builder(MainScreen.this);
    mContext = getApplicationContext();
    /**
     * by the help of inflater my ordre is showing in list view
     */
    inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    orderDialogLayout = inflater.inflate(R.layout.my_order_list,(ViewGroup)findViewById(R.id.order_list_root));
    orderList = (ListView) orderDialogLayout.findViewById(R.id.order_list);

    ibOrderDelete = (ImageButton)orderDialogLayout.findViewById(R.id.deleteOrder);
    tvPrice = (TextView) orderDialogLayout.findViewById(R.id.order_list_total);
    tvTaxes = (TextView) orderDialogLayout.findViewById(R.id.order_list_taxes);
    tvTotal = (TextView) orderDialogLayout.findViewById(R.id.order_list_grand_total);
    Button bclose = (Button) orderDialogLayout.findViewById(R.id.close);
    Button bPlaceOrder = (Button) orderDialogLayout.findViewById(R.id.my_order_placeorder);

    bclose.setOnClickListener(new OnClickListener() {

        public void onClick(View v) { 
            orderDialog.dismiss();   
            System.out.println(" click on close button");


        }      
    });

    /**      
     * click of place order to kitchen    
     */   
    bPlaceOrder.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            System.out.println("Place order click");

            palceMyOrdertoServer();
            new SendOrderFromTable().execute();
            System.out.println("place order to server is called");
            String msg = "Your Order is Successfully placed to Kitcken";
            Message msgObject = new Message();
            msgObject.what = 1;             
            msgObject.obj = msg;
            addMenuItemHandler.sendMessage(msgObject);
        orderDialog.dismiss();

        }
    });}

My f2() is for some Cursor work with data base

    F2{
   // many stuff to be here populate data from cursor and bind it with adapter
    // no any issue in this mehod
     }

Now finally I am calling f3()

      F3{
        builder.setView(orderDialogLayout);
    orderDialog = builder.create();
    orderDialog.show();
       }

Now i am going to explain all my problem f1() method is for initialization f2() is for populate data and f3() to show customize alert dialog . Why my

       orderDialog.dismiss();

is not working for me.Even though i am able to see my logcat with message

        "Click on close button"

That means execution is going on dismiss() method then why customize alert dialog didn't close at click. Thanks in advance to all

DJhon
  • 1,548
  • 3
  • 22
  • 39

1 Answers1

0

You should add final in your orderDialog private variable.

muntasir2000
  • 204
  • 1
  • 3
  • 11
  • @muntssir....Thanks for your response..If i declare as final. then how could i initialize orderDialog in f3() block...? – DJhon Oct 27 '13 at 09:51
  • Try reconsidering your approach. [Here](http://stackoverflow.com/questions/7423028/java-local-variable-visibility-in-anonymous-inner-classes-why-is-final-keywo) is why it should be final – muntasir2000 Oct 27 '13 at 10:02
  • I must say your coding style is not very pleasant to read. Reconsidering it may be a good idea. – muntasir2000 Oct 27 '13 at 10:04
  • @muntasir..,,,..I am checking your link ..Thanks...May i ask a question , What is not pleasant in my coding style? – DJhon Oct 27 '13 at 11:50
  • @muntasir..and if it is issue of final,,, then why i am getting "Click on close button" in my logcat? THat means click event perfomed very well.... – DJhon Oct 27 '13 at 11:54
  • 1
    @BlueGreen implement `DialogInterface.OnDismissListener` override `onDismiss(DialogInterface dialog)` and log something there see if it logs anything. `alertDialog.setOnDismissListener(ActivityName.this)` – Raghunandan Oct 28 '13 at 07:15
  • @Raghunandan...Thanks..I want to say one thing.your are one of help-full guy in this portal.Let me check your suggestion. – DJhon Oct 28 '13 at 07:36
  • @Raghunandan... when i am implementing this showing null pointer exception – DJhon Oct 28 '13 at 07:54
  • orderDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // TODO Auto-generated method stub System.out.println(" my dismiss listener is called"); } }); – DJhon Oct 28 '13 at 07:55