Re: [android-developers] Re: Showing Custom Dialog

2010-02-10 Thread TreKing
On Wed, Feb 10, 2010 at 12:17 AM, YCH yip@gmail.com wrote:

 After replacing getApplicationContext() with this, I am still having
 the same problem.

 Any ideas? Thanks!


Try using AlertDialog.Builder to create your dialog.

-
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Showing Custom Dialog

2010-02-09 Thread YCH
After replacing getApplicationContext() with this, I am still having
the same problem.

Any ideas? Thanks!

On Feb 9, 3:02 am, TreKing treking...@gmail.com wrote:
 DO NOT use getApplicationContext(), use *this*.



 On Sat, Feb 6, 2010 at 10:59 PM, YCH yip@gmail.com wrote:
  Hi,

  I am new to android development and is having some problems on showing
  a custom dialog. My development environment is sdk 1.5 with eclipse.

  In the menu, if user click on the first button, I want to show a
  dialog.

     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
         case MENU_ADD
                 this.showDialog(1);
             return true;
         case MENU_QUIT :
                 this.finish();
             return true;
         }
         return false;
     }

     protected Dialog onCreateDialog(int id) {
         Dialog dialog;
         switch(id) {
         case 1:
                 dialog = new Dialog(this.getApplicationContext());
                 dialog.setContentView(R.layout.input_dialog);
                 TextView t = (TextView)
  dialog.findViewById(R.id.TextView01);
                 Button b = (Button) dialog.findViewById(R.id.Button01);
             break;
         default:
             dialog = null;
         }
         return dialog;
     }

  I know that the showDialog() will go to onCreateDialog(), but when I
  try to execute it in the emulator, it keeps saying that ERROR/
  AndroidRuntime(789) at the line this.showDialog(1);

  Is there anything important things missed? Would be grateful if there
  is some ideas on it!

  Thanks,
  YCH

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 --

 -
 TreKing - Chicago transit tracking app for Android-powered 
 deviceshttp://sites.google.com/site/rezmobileapps/treking

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Showing Custom Dialog

2010-02-09 Thread YCH
Thanks for your info.
The implementation of my input box class is

public class InputDialog extends Dialog  {

 public InputDialog(Context context) {
  super(context);
 }

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mydialog);
 }
}



On Feb 10, 2:32 pm, venkat ranjit ranjit0...@gmail.com wrote:
 Hi friend ,

    i am sending code that displays alertDialog using AlertDialog class ok

 package no.freedommedia.featurebooster.cmd;

 import java.util.ArrayList;
 import java.util.concurrent.Semaphore;

 import android.app.Activity;
 import android.app.AlertDialog.Builder;
 import android.content.Context;
 import android.content.DialogInterface;

 import android.util.Log;

 //public class MyAlertBox extends AlertDialog implements Runnable
 public class MyAlertBox extends Activity
 {

     public  int m_query = -1;
     String m_title;
     String m_mymessage;
     ArrayListString m_buttonNames;

     Context m_context;
     Semaphore m_smp;
     MyAlertBox(){

     }

     public MyAlertBox(String title,String mymessage,ArrayListString
 softkeyvalue, Context context)
     {

         m_title = title;
         m_mymessage = mymessage;
         m_buttonNames = softkeyvalue;

         m_context =  context;
         newThr nt = new newThr(m_title,m_mymessage,m_buttonNames);
         Thread t= new Thread(nt);

         t.start();

         try
         {
             synchronized (this)
             {
                 Log.i(hello, Constructor);
                   this.wait();

             }

         }
         catch (InterruptedException e)
         {

             e.printStackTrace();
         }

         if(getDialogResult() != -1)
         {
             this.notify();
         }

     }

     public void settingAlertBox(String title,String
 mymessage,ArrayListString softkeyvalue)
     {
         Log.i(hello, this is settingAlertBox  + softkeyvalue.size());
         Builder ab= new Builder(m_context);
         if(softkeyvalue.size()  1)
         {

             ab.setTitle(title);
             ab.setMessage(mymessage);

             Log.i(hello, this is first button before calling set+ve
 button);

             ab.setPositiveButton((String)softkeyvalue.get(0),new
 DialogInterface.OnClickListener()
               {
                  public void  onClick(DialogInterface dialog, int
 whichButton)
                  {
                      Log.i(hello, this is first button, first button);

                     m_query = 0;

                  }
               }

               );

             Log.i(this is first button,after calling set+ve button);

             ab.setNegativeButton((String)softkeyvalue.get(1),new
 DialogInterface.OnClickListener()
               {
                  public void onClick(DialogInterface dialog, int
 whichButton)
                  {

                      Log.i(hello, this is 2nd button, second button);

                      m_query = 1;

                  }
               }
               );

              ab.show();

              Log.i(hello, this is first button,after calling setnegative
 button);

              Log.i(tag, m_query+getDialogResult());

          }//if
      else
      {
          ab.setTitle(title);
          ab.setMessage(mymessage);
          ab.setPositiveButton((String)softkeyvalue.get(0),new
 DialogInterface.OnClickListener()
               {
                  public void  onClick(DialogInterface dialog, int
 whichButton)
                  {
                     Log.i(this is single button,Single button);

                     m_query = 0;

                  }
                  }
               );

          ab.show();
               }

      }//else

     public int getDialogResult()
     {

         return m_query;

     }

 }
 On Sun, Feb 7, 2010 at 3:56 PM, YCH yip@gmail.com wrote:
  Hi,

  I encountered a message like below when opening a custom dialog
  through menu option.

  02-07 16:37:45.478: ERROR/BACKGROUND_PROC(1007):
  android.view.WindowManager$BadTokenException: Unable to add window --
  token null is not for an application

  Using the latest sdk with 1.5 emulator.

  Any ideas?

  Thanks!

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group