-1

I am trying to implement a dialog box that pops up when a button is pressed by the user. This currently works, however the buttons I have included in the pop up are unresponsive. I have tried the following code to try and resolve the problem.

public void showDialog()
{
    final Dialog dialog= new Dialog(context);
    dialog.setContentView(R.layout.dialog_info);

    infoView=(EditText) dialog.findViewById(R.id.infoView);
    infoView.setFocusable(false);
    infoView.setText("");

    dialog.setTitle(aList.get(count).toTitle());
    infoView.append(aList.get(count).toDescription());


    Button back=(Button)findViewById(R.id.back);
    Button reminder=(Button)findViewById(R.id.reminder);


    Log.e(TAG,"Testing click 1.5");

   back.setOnClickListener(new OnClickListener()
    {
       @Override
        public void onClick(View v)
        {
            Log.e(TAG,"Testing click 2");
            dialog.dismiss();
        }
    });
   dialog.show();
}

showDialog() gets called after a button (back) in the first view is pressed

    public void onClick(View v) {

    for (count =0;count<aList.size();count++)
        {
        if (v==buttons.get(count))
            {
             Log.e(TAG,"Testing click -1.1");
            showDialog();

            }
        }

} 
algorhythm
  • 3,304
  • 6
  • 36
  • 56
  • What is your IDE? Could be a Eclipse issue. – smk Mar 28 '13 at 17:16
  • possible duplicate of [@Override compile error, implementing an interface (eclipse jdk1.6.0\_23 linux)](http://stackoverflow.com/questions/4995780/override-compile-error-implementing-an-interface-eclipse-jdk1-6-0-23-linux) – Andy Thomas Mar 28 '13 at 17:19
  • Nah turns out the override wasn't even the problem! – algorhythm Mar 28 '13 at 18:02

2 Answers2

0

Correct me if I understood wrong,

your button back and reminder are a part of the dialog, so you should be getting a null pointer exception. Try finding your buttons like this

 Button back=(Button)dialog.findViewById(R.id.back);
 Button reminder=(Button)dialog.findViewById(R.id.reminder);

EDIT: By doing this you'll find the button inside the dialog. If you don't do this android will try to find the button in Activity itself and not the dialog .

For the Override problem please recheck that you've done the right import. (there are two kinds of import for View.onClickListner I don't remember their name right now.) You can delete your import associated with View.Onclick and try to re-import the correct package.

If this is not the case then I might have misinterpreted your question. You can check your Java Compliance level and see if its on 1.6 or not. You can check this by going to your project properties under Java Compliance Level

Parvaz Bhaskar
  • 1,367
  • 9
  • 29
  • Thanks for the reply, the level is 1.6. The buttons have already been declared in the xml file dialog_info which I have set dialog.setContentView(R.layout.dialog_info); above – algorhythm Mar 28 '13 at 17:31
0

What version of Java are you using?

Right-click your project Go to Properties Go to Java Compiler Enable project specific settings Select 1.6 for Java compliance level

This will fix the @Override errors. If you want to use another version, you can just remove all @Override annotations.

labatyo
  • 486
  • 8
  • 17